Skip to content

Instantly share code, notes, and snippets.

@ahmed-anas
Created February 11, 2017 04:44
Show Gist options
  • Select an option

  • Save ahmed-anas/2c5d3fe08ff27ffb276d8720677ad3f5 to your computer and use it in GitHub Desktop.

Select an option

Save ahmed-anas/2c5d3fe08ff27ffb276d8720677ad3f5 to your computer and use it in GitHub Desktop.

Revisions

  1. ahmed-anas created this gist Feb 11, 2017.
    22 changes: 22 additions & 0 deletions custom_bind.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@

    let myObj = {
    str: 'Original Scope',
    foo: function() {
    console.log(`my scope is ${this.str}.`);
    }
    }

    function myBind(func, scope){
    for(let prop in scope){
    this[prop] = scope[prop];
    }

    this.funcToCall = func;

    return this.funcToCall;

    }

    myObj.foo();
    var newFoo = myBind(myObj.foo, {str: 'Overwridden Scope'});
    newFoo();