JSFiddle - React, Tailwind, and code Playground
JavaScript
function printobject(msg,obj) {
if(msg) {
document.write("<b>"+msg+"</b><br>");
document.write("<hr><br>");
}
for ( var prop in obj ) {
if(obj.hasOwnProperty(prop)){
if(obj[prop].toString() !== "[object Object]"){
document.write(prop + " : " + obj[prop] + "<br>");
}else{
document.write("<b>"+prop + " : " + obj[prop]+"</b><br>");
printobject("",obj[prop]);
}
}
}
if(msg) {
document.write("<br><hr><br>");
}
};
var base = {
extend: function() { //extend this Object
var args = Array.prototype.slice.call(arguments);
printobject("Arguments to Extend",args)
var that = Object.create(this,(args?args.shift():{}));
var arg = args.shift() || {} ;
printobject("Copy Properties to New Object",arg);
for(var prop in arg) {
that[prop] = arg[prop];
}
// Object.freeze(that);
return that;
},
create: function() { //Creates new instances of the Object
var that = Object.create(this,{
extend:{value:null,writable:false,configurable:false}, //sets extend and create to null so you cant create a new instance when used create ( use extend instead);
create:{value:null,writable:false,configurable:false}
});
that.init.apply(that,arguments); //call init function for the new created object;
return that;
},
init: function() { printobject("No Initfunction supplied for New Object",this);} // Empty init function for fallback
}
var Human = base.extend({ //BEFR = base.extend(...
name:{value:"test"}
},{
init:function(name) {alert(name + " has been created");this.name = name;},
test:"Abcd Public",
walk:function (){alert(this.name + " walks");}
});
//TableViewCollection == BEFR.extend()
var Human1 =...