Inheritance is a concept which says you can create a class from another class if you would like to use its properties. A parent cantalk and caneat, so can the child because child “is a” subclass of Parent. While most programming languages have the concept of classes, in javascript its all about objects inheriting from other …
Month: April 2016
//1. using curly braces var myVar = {}; //2. using new operator var myVar = new Object(); //3. using the Object.create method var myVar = Object.create(Object.prototype);
for..in is used to iterate through the properties in our javascript objects. The syntax for (variable in object) { //do something with the variable } Example “use strict” var obj = {a:1, b:2, c:3}; for (var prop in obj) { console.log(“obj.” + prop + ” = ” + obj[prop]); } // Output: // “obj.a = 1” …
Different ways of setting a value to a Javascript object //create an object var myVar = {}; //1. set value using dot myVar.key = “myvalue”; //2. set value using square brackets myVar[“key2”] = “myValue2″ //3. set value using defineProperty Object.defineProperty(myVar,”key3”,{ value : “myValue3” }); Setting values using the dot syntax or square brackets is pretty easy …