JSFiddle - React, Tailwind, and code Playground
by chrisallenaaker
JavaScript
"use strict";
var OO = {
// Class Maker
Class: function () {
var len = arguments.length,
data = arguments[len - 1],
Klass,
Private = {};
if (data.constructor === Object) {
Klass = function () {};
} else {
Klass = data.constructor;
delete data.constructor;
}
OO.extendPublic(Klass.prototype, data.Public);
OO.extendPrivate(Private, data.Private);
return Klass;
},
extendPrivate: function (target, source) {
// Copy Private over
var prop;
for (prop in source) {
target[prop] = source[prop];
}
},
extendPublic: function (target, source) {
// Copy public over
var prop;
for (prop in source) {
target[prop] = source[prop];
}
}
};
// Define a Class
var Person = OO.Class ({
constructor: function (name, age) {
},
Public: {
getName: function () {
return "connect_here";
},
getAge: function () {
return "connect_here";
}
},
Private: {
name: '',
age: ''
}
});
var Josh = new Person('josh', 22);
alert(Josh.getName() + ' | ' + Josh.getAge());
alert(Josh.age + ' | ' + Josh.name);