Last active
August 29, 2015 13:56
-
-
Save techwraith/9239209 to your computer and use it in GitHub Desktop.
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 bind = require('lodash.bind') | |
var Base = require('ribcage-view') | |
window.foo = 'baz' | |
var SubThing = Base.extend({ | |
action: function () { | |
this.options.action() | |
} | |
}) | |
var Thing = Base.extend({ | |
myAction: function () { | |
console.log(this.foo) | |
} | |
, afterInit: function () { | |
this.foo = 'bar' | |
} | |
, afterRender: function () { | |
this.subThing = new SubThing({ | |
action: myAction // logs 'baz' | |
action: bind(myAction, this) // logs 'bar' | |
}) | |
} | |
}) | |
var myThing = new Thing() | |
myThing.render() |
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 bind = require('lodash.bind') | |
var myCallback = function () { | |
console.log(this.foo) | |
} | |
window.foo = 'baz' | |
var Thing = function () { | |
this.foo = 'bar' | |
} | |
var myThing = new Thing() | |
var bound = bind(myCallback, myThing) | |
bound() // logs 'bar' | |
myCallback() // logs 'baz' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment