Skip to content

Instantly share code, notes, and snippets.

@techwraith
Created July 27, 2011 07:20
Show Gist options
  • Save techwraith/1108845 to your computer and use it in GitHub Desktop.
Save techwraith/1108845 to your computer and use it in GitHub Desktop.
What scope is name, foo, and bar in?
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