.call() and .Apply()
JavaScript
var one = {
name: "Obj One",
func: function(){
alert(this.name);
}
};
var two = {
name: "Obj two",
call: function( x, y){
alert(this.name + " " + x + " " + y);
}
};
var three = {
name: "Obj three"
};
// execute func as if it where attached to two
//one.func.call(two);
//one.func.apply(two);
// execute call as if it where attached to three
two.call.apply(three,[ 1,2]);//passes an array
two.call.call(three, 1,2);//argument list