I have been cuddling with OOP programming. JavaScript seemed like a good start. I went to w3schools.com.
function person(first, last, age, eye) {
this.firstName = first;
this.lastName = last;
this.age = age;
this.eyeColor = eye;
this.name = function() {
return this.firstName + " " + this.lastName
this.capitalize = function() {
return this.firstName.charAt(0) + " " + this.lastName.charAt(0);
}
};
}
var myFather = new person("John", "Doe", 50, "blue");
document.getElementById("demo").innerHTML = "My father is <b>" + myFather.name() + "</b>";
document.getElementById("demo1").innerHTML = "His captial letters are <b>" + myFather.name.capitalize() + "</b>";
document.getElementById("demo2").innerHTML = "His captial letters are <b>" + myFather.name().capitalize() + "</b>";
How can I manage to let last two lines work? So far I get the first line to work because it was actually rip-off from W3S. I get many, many, errors. Most of them are, the problem itself. I know how to make one-layered OOP program execution, like above myFather.eyeColor();
. But I would like to learn multiple layered object programming. Something like document.getElementById("id").innerHTML("woa");
. Object and two functions. Three layered call. Another example is object.style.transform="rotate(7deg)"
. Object, 1 method, 1 assignment. Another three layered call.
TLTR: How do I display first letter of first name and first letter of last name using script above?
I've been through W3School's tutorial about how to make one layered object call, do you maybe know a website, where they explain multi-layered object calls, like very long ones and that require many layers, for example el.visuality.ref("material_renderer").color="#000";