Difference between revisions of "Constructors"

From rbachwiki
Jump to navigation Jump to search
Line 6: Line 6:
     this.yearOfBirth = yearOfBirth;
     this.yearOfBirth = yearOfBirth;
     this.job = job;
     this.job = job;
    this.calculateAge = function() {
        console.log(2016 - this.yearOfBirth);
    }
}
}




var john = new Person('john', 1967, 'teacher');
var john = new Person('john', 1967, 'teacher');
john.calculateAge();


</pre>
</pre>
==[[#top|Back To Top]]-[[Main_Page| Home]] - [[Java Script|Category]]==
==[[#top|Back To Top]]-[[Main_Page| Home]] - [[Java Script|Category]]==

Revision as of 17:15, 6 November 2016

Function Constructor

var Person = function(name, yearOfBirth, job){
    this.name = name;
    this.yearOfBirth = yearOfBirth;
    this.job = job;
    this.calculateAge = function() {
        console.log(2016 - this.yearOfBirth);
    }
}


var john = new Person('john', 1967, 'teacher');
john.calculateAge();

Back To Top- Home - Category