Last active
September 26, 2016 07:18
-
-
Save nchevobbe/cadef064dda7e341458cbb3ab5f1453f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
function A (name) { | |
this.name = name; | |
this.sayMyName = this.sayMyName.bind(this); | |
} | |
A.prototype = { | |
sayMyName: () => { | |
console.log(this.name); // -> undefined | |
} | |
}; | |
function B (name) { | |
this.name = name; | |
this.sayMyName = this.sayMyName.bind(this); | |
} | |
B.prototype = { | |
sayMyName: function() { | |
console.log(this.name); | |
} | |
}; | |
let test = { | |
a: new A("a"), | |
b: new B("b"), | |
} | |
test.a.sayMyName(); | |
test.b.sayMyName(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment