Skip to content

Instantly share code, notes, and snippets.

@mde
Created January 14, 2012 03:48
Show Gist options
  • Save mde/1610175 to your computer and use it in GitHub Desktop.
Save mde/1610175 to your computer and use it in GitHub Desktop.
> var foo = {a: function () { console.log(this.b); }, b: true};
> foo.b;
true
> foo.a;
[Function]
> foo.a();
true
> var bar = foo.a;
> foo;
{ a: [Function], b: true }
> bar;
[Function]
> bar();
undefined
> var b = 'hello';
> bar();
hello
> var baz = {b: false};
> bar.call(baz);
false
> var proxy = function (obj, func) { return function () { func.apply(obj, arguments) } };
> var qux = proxy(baz, bar);
> qux();
false
> var a = {};
> typeof a;
'object'
> var b = function () {};
> var c = new b();
> typeof c;
'object'
> c;
{}
> var b = function () { return {a: true} };
> var c = new b();
> c;
{ a: true }
> var c = b();
> var b = function () {};
> var c = b();
> typeof c;
'undefined'
> var c = new b();
> typeof c;
'object'
> var c = new (function () {})();
> typeof c;
'object'
> var foo = 'myString';
> var bar = {];
...
> var bar = {};
> bar[foo] = 'hello';
'hello'
> bar;
{ myString: 'hello' }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment