Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //This code does not work:
- var x = {
- get: (msg1) => (msg2) => {
- return this.val; //this refers to window here.
- },
- val: "Vorcan"
- }
- console.clear();
- //Prints undefined
- console.log(x.get("")(""));
- //This code works
- var x = {
- get: function(msg1){
- return (function(msg2){
- return this.val;
- }).bind(this);
- },
- val: "Vorcan"
- }
- console.clear();
- //Prints "Vorcan"
- console.log(x.get("")(""));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement