JSFiddle - React, Tailwind, and code Playground
by gschutz
JavaScript
var Jack;
Jack = function() {
console.log('jack init');
}
Jack.helper = function() {
this.exit = '';
console.log(this);
}
Jack.extend = function() {
var modules, methods, key, i
/* get list of modules */
modules = [].slice.call(arguments)
/* get object with extensions */
methods = modules.pop()
for (i = modules.length - 1; i >= 0; i--)
if (modules[i])
for (key in methods)
modules[i].prototype[key] = methods[key]
}
Jack.create = function(name) {
var k = {};
k[name] = function() {};
return k[name];
}
Jack.invent = function(opt) {
opt = (typeof opt === 'function') ? opt() : opt;
var initializer = (typeof opt.create === 'function') ?
opt.create :
function() {
this.constructor.call(this, Jack.create(opt.create))
};
if (opt.inherit)
initializer.prototype = new opt.inherit
if (opt.extend)
Jack.extend(initializer, opt.extend)
if (opt.construct)
Jack.extend(opt.parent || Jack.Container, opt.construct)
return initializer
}
var Step = Jack.invent(function() {
var child = {};
return {
create: function Step() {
this.created = "created";
this.gizmo = function() {
return created;
}
child = this;
},
inherit: function Walk() {
this.hello = "hello world";
this.parent = function() {
return child.__proto__;
}
this.child = function() {
return child;
}
},
extend: {
created: "extended"
}
}
});
var igor = new Step();
console.log(igor.created);
console.log(igor.hello);
console.log(igor.parent().created);
console.log(igor.parent().child());
console.log(igor instanceof Step);