Skip to content

Instantly share code, notes, and snippets.

@rolldone
Last active July 11, 2020 08:16
Show Gist options
  • Save rolldone/0f6bb10fcd139a7728534816c09d0efe to your computer and use it in GitHub Desktop.
Save rolldone/0f6bb10fcd139a7728534816c09d0efe to your computer and use it in GitHub Desktop.
var Original = {
extend : function(props = null) {
var newOne = Object.assign({}, this);
newOne.super = Object.assign({}, newOne);
if (props != null) {
for(var key in props){
if(props[key].toString().includes('.super') == false){
if(key != 'construct'){
console.log('key',key);
newOne.super[key] = props[key];
}
}
}
return (Object.assign(newOne, props));
}
return newOne;
},
construct : function(){
console.log('base construct')
},
new : function(...props){
this.construct.call(this,...props);
return Object.assign({},this);
},
}
/* Extend for the first time */
var testExtendObject = Original.extend({
construct : function(){
console.log('testExtendObject constructor called');
this.super.construct();
},
getOne : function(){
console.log('testExtendObject - getOne called!');
}
})
/* Extend for the second time */
var test2ExtendObject = testExtendObject.extend({
construct : function(){
console.log('test2ExtendObject - constructor called!');
this.super.construct();
// Nested called super
// this.super.super.construct();
},
getOne : function(){
console.log('test2ExtendObject - getOne called!');
this.super.getOne();
}
})
/* Run it! */
var test2 = test2ExtendObject.new();
test2.getOne();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment