point.x=3; //property
point.y=4;
point.getPosition=function(){ //method
alert(this.x+","+this.y);
} ;
→ the result is 3,4
point.getPosition();
→ call the function. So from the example above, we'll get "3,4"
var trip=new Object();
trip.name="Couple Trip";
trip.score=70;
trip.outdoor=function(){ // Camping at outdoor so that we can enjoy natural environment.
this.score=this.score+10;
};
trip.rainyDay=function(){ //Rainy day is a bit troublesome that we can't go hiking.
this.score=this.score-5;
};
trip.snacksnBBQ=function(){ //Delicious food is always welcome!
this.score=this.score+20;
};
trip.napping=function(){ //Chilled camping always needs a nap.
this.score++;
};
trip.report=function(){ //
alert(this.name+":"+this.score)
};
So at the end, the way we count the score of an ideal trip would be...
trip.outdoor();
trip.rainyDay();
trip.snacksnBBQ();
trip.napping();
trip.report();
→ The result is 96!
Feel free to comment and share your ideas below to learn together!
If you guys find this article helpful, please kindly do the writer a favor — LIKE this article.