January 2019
Beginner
210 pages
4h 47m
English
Because JavaScript is a dynamic programming language, we can add properties and methods to an instance of an object at runtime; and they don't need to be part of the object (class) itself:
const name = "Remo";const surname = "Jansen";function Person(name, surname) { // instance properties this.name = name; this.surname = surname;}const person1 = new Person(name, surname);person1.age = 27;
We have defined a constructor function for an object named Person, which takes two variables (name and surname) as arguments. Then we have created an instance of the Person object and added a new property named age to it. We can use a for…in statement to check the properties of person1 at runtime:
for(let property ...
Read now
Unlock full access