You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jan 13, 2022. It is now read-only.
oatkiller edited this page Sep 13, 2010
·
3 revisions
description
returns a new function that does the same as the first, but is bound to the passed execution context
usage
(function () {// an object with a 'name' property
var person1 = {
name: 'Robert'
};
// another object with a 'name' property
var person2 = {
name: 'Roy'
};
// a function that returns the name of the object it belongs to.
// only it doesnt belong to an object!
var get_name = function () {
return this.name;
};
// with bind, a function acts like its on an object, even tho its not
var get_person1s_name = get_name[o.bind](person1),
get_person2s_name = get_name[o.bind](person2);
get_person1s_name(); // returns 'Robert'
get_person2s_name(); // returns 'Roy'
})();