Skip to content

Instantly share code, notes, and snippets.

@bloodyowl
Last active August 29, 2015 13:57
Show Gist options
  • Save bloodyowl/9769514 to your computer and use it in GitHub Desktop.
Save bloodyowl/9769514 to your computer and use it in GitHub Desktop.
noThis
var splice = [].splice
, baseClass = {
create : function(){
return Object.create(this)
},
method : function(name, fn){
Object.defineProperty(this, name, {
writable : true,
configurable : true,
enumerable : false,
value : function(){
splice.call(arguments, 0, 0, this)
return fn.apply(null, arguments)
}
})
}
}
var myInstance = baseClass.create()
myInstance.method("setFoo", function(instance, value){
instance.foo = value
})
myInstance.setFoo("bar")
myInstance.foo // "bar"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment