ECMA6
Inheritence in ecma6
by Samar Pattanayak
JavaScript
class song{
constructor(title,track){
this.title= title;
this.track= track;
this.playing= false;
}
start() {
this.playing= true;
console.log(this.playing);
}
stop() {
this.playing= false;
console.log(this.playing);
}
end(){
console.log("ghj")
}
}
var songob= new song("tere","track1");
songob.start();
//ECMA 5
function parent(name,age){
this.name= name;
this.age=age;
this.say=function(){
console.log(this.name +"has "+ this.age);
};
}
function child(name,age,qual){
parent.call(this,name,age);
this.qual= qual;
this.sayChild= function(){
console.log(this.name +" having age of " + this.age +" doing "+this.qual);
}
}
var parentObject= new parent('samr',26);
parentObject.say();
child.prototype = Object.create(parent.prototype);
child.prototype.constructor = child;
var chilObject= new child('Halllalll',36,'Phd');
chilObject.sayChild();
//ECMA 6
class parent6{
constructor(name,age){
this.name= name;
this.age=age;
}
say(){
console.log(this.name +"has "+ this.age);
}
}
class child6 extends parent6{
constructor(name,age,qual){
super(name,age);
this.qual= qual;
}
sayChild(){
console.log(this.name +" having age of " + this.age +" doing "+this.qual);
//console.log `${this.name} + ${this.age}`;
}
}
var parentObject6= new parent6('Baisa',23);
parentObject6.say();
child6.prototype = Object.create(parent6.prototype);
child6.prototype.constructor = child6;
var chilObject6= new child6('Imran',36,'Doct');
chilObject6.sayChild();
console.log(i);
for(var i=0; i<4; i++){
console.log(i)
}
(function consDemo(){
const admin="samar";
console.log(admin);
//u cant change a const value as its readonly;
//admin="kumar";
const obj={name : "Darling"};
//u can change a property value of any constant object;
obj.name="SW and its value got changed";
console.log(obj.name );
})();
//
var person = {
firstName: "Andrew",
lastName: "Chalkley"
}
function getFirstName({firstName}) {
...