Skip to content

Instantly share code, notes, and snippets.

@techwraith
Last active August 29, 2015 13:56
Show Gist options
  • Save techwraith/9239209 to your computer and use it in GitHub Desktop.
Save techwraith/9239209 to your computer and use it in GitHub Desktop.
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()
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