javascript - do not understand object oriented programming -


i have looked @ number of tutorials i'm still struggling following code, can please explain code. can please explain each part , oit does.

function person (name, age) {     this.name = name;     this.age = age; }   var agedifference = function(person1, person2) {     return person1.age - person2.age; }  var alice = new person("alice", 30); var billy = new person("billy", 25);  // difference in age between alice , billy using our function var diff =  

function person(name, age) { // define _constructor_ called _person_     this.name = name;        // constructor sets instance property _name_     this.age = age;          // constructor sets instance property _age_ } // when invoked _new_, creates an..   // ..object instance of person  var agedifference = function (person1, person2) { // function (expression)     return person1.age - person2.age;  // returns difference..  }                                      // ..between _age_ properties  var alice = new person("alice", 30); // new instance of _person_ var billy = new person("billy", 25); // new instance /* _alice_ looks    |    _billy_ looks      {                       |      {          age: 30,            |          age: 25,          name: "alice"       |          name: "billy"      }                       |      } */ // difference in age between alice , billy using our function var diff = agedifference(alice, billy); // passing instances above..                                         // ..into function expression 

Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -