#20 JS: Object Fundamentals

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!
https://ithelp.ithome.com.tw/upload/images/20210919/20130362X62BkgAvUX.png

Music of Today: Here I Stand by The Shang


Like/Share/Follow

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./images/emoticon/emoticon12.gif


<<:  Day5 工作分解WBS怎麽拆

>>:  Day 20. Hashicorp Nomad: Docker driver image behavior

Scanners API-总金额篇

这个API可以取得总金额的排名, 步骤如下: (1)汇入需要的库 import shioaji as...

[DAY 13] CNN的实作以及 Classification 的应用例子

前言 我们已经知道了组成一个简单的 CNN 做 classification 所需要的部件了,那麽接...

关於取得旧版 macOS 这件事

想要降刷 macOS 版本,或是处理 Fusion Drive,该怎麽办?那里有资源?或是那边有官方...

Kotlin Android 第19天,从 0 到 ML - RecyclerView 动态列表

前言: RecyclerView 可以轻松高效地显示大量数据。 RecyclerView回收这些单独...

[自然语言处理基础] 语法分析与资讯检索 (II)

前言 上一回我们将词性标签依序排列建构出片语组块( phrase chunk ),描绘出相应的分析树...