Skip to content

Instantly share code, notes, and snippets.

@c4milo
Created May 18, 2012 23:45
Show Gist options
  • Select an option

  • Save c4milo/2728203 to your computer and use it in GitHub Desktop.

Select an option

Save c4milo/2728203 to your computer and use it in GitHub Desktop.

Revisions

  1. c4milo created this gist May 18, 2012.
    19 changes: 19 additions & 0 deletions why.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    var MyClass = function() {
    this.cosa = 0;
    console.log('constructor');
    };

    (function() {
    var func1 = function() {
    console.log('func1');
    console.log(this.cosa);
    }.bind(this);

    this.func2 = function() {
    console.log('func2');
    func1();
    };
    }).call(MyClass.prototype);

    var i = new MyClass();
    i.func2();