Skip to content

add lexical this, args, and return#10

Open
sezgi wants to merge 1 commit intoyoung:masterfrom
sezgi:patch-1
Open

add lexical this, args, and return#10
sezgi wants to merge 1 commit intoyoung:masterfrom
sezgi:patch-1

Conversation

@sezgi
Copy link

@sezgi sezgi commented Jun 10, 2021

add arrow fn to get lexical this for brevity; args for e.g. boundFn(5); return value of original fn

add arrow fn to get lexical this for brevity; args for e.g. boundFn(5); return value of original fn
@sezgi
Copy link
Author

sezgi commented Jun 10, 2021

For example:

Function.prototype.bind = function(context) {
    return (...args) => {
        return this.apply(context, args);
    }
}

let foo = {
    base: 3,
    myFunc(num) {
        return this.base + num;
    }    
}

let newFunc = foo.myFunc.bind({base: 6});
console.log('old', foo.myFunc(5));
console.log('new', newFunc(5));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant