Skip to content

Instantly share code, notes, and snippets.

@nchevobbe
Last active September 26, 2016 07:18
Show Gist options
  • Save nchevobbe/cadef064dda7e341458cbb3ab5f1453f to your computer and use it in GitHub Desktop.
Save nchevobbe/cadef064dda7e341458cbb3ab5f1453f to your computer and use it in GitHub Desktop.
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