// constructor function
function Person (name) {
// assigning parameter values to the calling object
this.name = name;
// defining method
this.greet = function () {
return ('Hello' + ' ' + this.name);
}
}
function add(c, d) {
return this.a + this.b + c + d;
}
var o = {a: 1, b: 3};
// The first parameter is the object to use as
// 'this', subsequent parameters are passed as
// arguments in the function call
add.call(o, 5, 7); // 16
// The first parameter is the object to use as
// 'this', the second is an array whose
// members are used as the arguments in the function call
add.apply(o, [10, 20]); // 34
// constructor function
function Person (name) {
// assigning parameter values to the calling object
this.name = name;
// defining method
this.greet = function () {
return ('Hello' + ' ' + this.name);
}
}
function add(c, d) {
return this.a + this.b + c + d;
}
var o = {a: 1, b: 3};
// The first parameter is the object to use as
// 'this', subsequent parameters are passed as
// arguments in the function call
add.call(o, 5, 7); // 16
// The first parameter is the object to use as
// 'this', the second is an array whose
// members are used as the arguments in the function call
add.apply(o, [10, 20]); // 34