Last active
August 29, 2015 13:57
-
-
Save bloodyowl/9769514 to your computer and use it in GitHub Desktop.
noThis
This file contains hidden or 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 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