[Learning]#20 JS: Object Fundamentals

Vida Lin
1 min readOct 8, 2021

What is an Object?

point.x=3; //property
point.y=4;
point.getPosition=function(){ //method
alert(this.x+","+this.y);
} ;

→ the result is 3,4

Use Object

point.getPosition();

→ call the function. So from the example above, we’ll get “3,4”

Example: The score of an ideal trip

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!

Music of Today: Here I Stand by The Shang

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Vida Lin
Vida Lin

Written by Vida Lin

PM, Relationship, Travel, or anything quirky but interesting.|Subscribe & buy Vida a drink @LikerLand, the bottom of each article. 在文章底下LikerLand訂閱、請Vida喝一杯飲料 ❤

No responses yet

Write a response