Reputation: 3599
How would I implement the same behaviour as below in es6
var grand_parent = {
parent: {
child: function () {
// logic
}.bind(this)
}
}
I tired the following, but I got a syntax error.
var grand_parent = {
parent: {
child() {
// logic
}.bind(this)
}
Upvotes: 0
Views: 339
Reputation: 664385
You would most likely use an arrow function:
var grand_parent = {
parent: {
child: () => {
// logic
}
}
};
where this
is lexically bound and works just as in your .bind(this)
scenario.
You cannot call .bind()
using the method syntax.
Upvotes: 2