Difference between revisions of "Constructors"

From rbachwiki
Jump to navigation Jump to search
Line 1: Line 1:


=Constructor=
=Function Constructor=
<pre>
<pre>
function Balance(current, deposit){
var Person = function(name, yearOfBirth, job){
  this.current = current;
    this.name = name;
  this.deposit = deposit;
    this.yearOfBirth = yearOfBirth;
  this.display=function(){
    this.job = job;
    current +=deposit;
    console.log(current);
  }
}
}
var balance = new Balance(100,24);
 
balance.display();
 
var john = new Person('john', 1967, 'teacher');
 
</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:08, 6 November 2016

Function Constructor

var Person = function(name, yearOfBirth, job){
    this.name = name;
    this.yearOfBirth = yearOfBirth;
    this.job = job;
}


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

Back To Top- Home - Category