Difference between revisions of "Classes"

From rbachwiki
Jump to navigation Jump to search
Line 7: Line 7:
this.job = job;
this.job = job;


}
// at a method
calculateAge(){
var age = new Date().getFullYear - this.yearOfBirth;
console.log(age);
}
static greeting(){
console.log('hey');
}
}
}
}


</pre>
</pre>
''' Create an instance of the class'''
const john = new Person('john', 1990, 'it');
''' Static methods are not inherited when you instantiate a new class '''
// call the static method
person.greeting();
==[[#top|Back To Top]]-[[Main_Page| Home]] - [[Java Script|Category]]==
==[[#top|Back To Top]]-[[Main_Page| Home]] - [[Java Script|Category]]==

Revision as of 18:51, 3 December 2016

Classes

class Person{
constructor(name, yearOfBirth, job){
this.name = name;
this.yearOfBirth = yearOfBirth;
this.job = job;

}
// at a method
calculateAge(){
 var age = new Date().getFullYear - this.yearOfBirth;
 console.log(age);
}
static greeting(){
console.log('hey');
}
}

Create an instance of the class

const john = new Person('john', 1990, 'it');

Static methods are not inherited when you instantiate a new class

// call the static method
person.greeting();

Back To Top- Home - Category