Created
June 15, 2011 18:25
-
-
Save mkuklis/1027738 to your computer and use it in GitHub Desktop.
JavaScript borrow method pattern
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var foo1 = { | |
name: "hello from foo1", | |
print: function () { | |
return this.name; | |
} | |
}; | |
var foo2 = { | |
name: "hello from foo2" | |
}; | |
// foo2 'borrows' print from foo1 | |
foo1.print.call(foo2); // hello from foo2 | |
//---------- | |
function f() { | |
var args = [].slice.call(arguments, 1, 3); // arguments borrow slice from Array | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment