JSFiddle - React, Tailwind, and code Playground
by hslincoln
HTML
<!-- Brief for OO programme: //1. Ok, make a class for a 'person' with personal details, //e.g address, name, dob, which are protected (private) //2. and that u can you can set and get. whatever. //then two other classes that inherit from it, //e.g employee and customer with some other data e.g position, orders, whatever. //Then create two arrays for each which can store these people (a database) -->
JavaScript
var warehousejobs = ['bullet-dodger', 'pile-driver', 'hired gun'];
// 1. Contructor first
function person(name, jobtitle, born) {
this.name = name;
this.jobtitle = jobtitle;
this.born = born;
if (typeof name !== 'string') {
alert("Were you born in a barn? That's not a name!");
return false;
} else {
alert("tasty, that's a name alright");
return name;
}
if (typeof jobtitle !== warehousejobs.indexOf()) {
alert("go boil your head!");
return false;
} else {
alert("stop standing around, get me a corrfy already!");
return jobtitle;
}
if (typeof born !== 'number') {
alert("This should be a number, and not contain letters");
return false;
} else {
return born;
}
}
var jimmyTheKnife = new person("jimmy", "hired gun", 1913);
// 2. using the prototype to add publicly to the object, on the fly
person.prototype.wag = null;
jimmyTheKnife.wag = "Minnie the Moocher";
// 3. Getting and setting stuff - unsure that this actually is...
function person(name, jobtitle, born) {
getValue: function () {
return this._value;
},
setValue: function (val) {
this._value = val;
}
}
// 6. The string business from
var exportperson = person.prototype.toString = function () {
return "This person:" + this.name + this.jobtitle "
};