Created
November 25, 2018 08:08
-
-
Save manojd929/ad6de9e6370488e792295878c3de239f to your computer and use it in GitHub Desktop.
this-js
This file contains 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
var obj = { | |
a: 5, | |
b: 10, | |
add: function() { | |
return this.a + this.b; | |
}, | |
}; | |
console.log('1: ', obj.add()); | |
var another = obj.add; | |
console.log('2: ', another()); | |
var anotherBound = obj.add.bind(obj); | |
console.log('3: ', anotherBound()); | |
var obj2 = { | |
c: 5, | |
d: 10, | |
add: { | |
e: 15, | |
fun: function() { | |
console.log('4: inner: ', this.c, this.d, this.e); | |
} | |
}, | |
subtract: function() { | |
this.e = 15; | |
console.log('5: outer: ', this.c, this.d, this.e); | |
return function() { | |
console.log('5: inner: ', this.c, this.d, this.e); | |
}; | |
}, | |
}; | |
console.log('4: ', obj2.add.fun()); | |
console.log('5: ', obj2.subtract()()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment