Created
July 27, 2011 07:20
-
-
Save techwraith/1108845 to your computer and use it in GitHub Desktop.
What scope is name, foo, and bar in?
This file contains 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 name = 'test' | |
var foo = 'foo'; | |
var bar = 'bar'; | |
var func = function(arg1, arg2) { | |
console.log(arg1, arg2, this.name); | |
}; | |
var obj = { | |
name: 'something new' | |
}; | |
func(foo, bar); // logs 'foo','bar',undefined | |
func.call(obj, foo, bar); // logs 'foo','bar','something new' | |
func.apply(obj, [foo,bar]); // logs 'foo','bar','something new' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment