Skip to content

Instantly share code, notes, and snippets.

@johnmckerrell
Created August 8, 2011 15:44
Show Gist options
  • Save johnmckerrell/1131992 to your computer and use it in GitHub Desktop.
Save johnmckerrell/1131992 to your computer and use it in GitHub Desktop.
Foo this demo
var blah = 'foo';
var myObject = {blah: 'I am myObject.foo'};
var sayFoo = function() {
console.log(this['blah']);
};
// give myObject a sayFoo property and have it point to sayFoo function
myObject.sayFoo = sayFoo;
myObject.sayFoo(); // logs 'I am myObject.foo' 12
sayFoo(); // logs 'foo'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment