Last active
June 6, 2016 14:21
-
-
Save trillerpfeife/f1c29c8c958b6be221289c6c069d7796 to your computer and use it in GitHub Desktop.
Extends a object method with a function, requires underscore.js
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 obj = { | |
init: function() { | |
console.log("init old"); | |
} | |
}; | |
var old_obj = {}; | |
_.extend(old_obj, obj); | |
console.log("'old' init():"); | |
obj.init(); | |
obj.init = function() { | |
old_obj.init.apply(this); | |
console.log("init extensions"); | |
}; | |
console.log("extended init():"); | |
obj.init(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment