Object Oriented and Functional Programming
1-Declare JavaScript Objects as Variables
var car = {
"wheels":4,
"engines":1,
"seats":5
};
var motorBike = {
"wheels":3,
"engines":1,
"seats":2,
// Only change code below this line.
};2-Construct JavaScript Objects with Functions
構造函數通常第一個字大寫,用來區分一般函數
this 指向創建出來的對象
var Car = function() {
this.wheels = 4;
this.engines = 1;
this.seats = 5;
};
// Only change code below this line.
var MotorBike = function() {
this.engines=1;
this.wheels=2;
this.seats=2;
};3-Make Instances of Objects with a Constructor Function
用
new function()來創建一個實力 instance
4-Make Unique Objects by Passing Parameters to our Constructor
5-Make Object Properties Private
建構函數內,自己的函數稱為方法,自己的特徵稱作屬性(忘了)
讓私有資料只能透過方法存取
6-Iterate over Arrays with map
有點詭異的迴圈
.map() 括號中是個 callback function
第一個參數是處理的元素,第二個是 index,第三個是陣列
好吧其實我看不太懂
7-Condense arrays with reduce
將陣列變成一個數字
reduce() 有兩個參數
第一個,callback function 有兩個參數,累加器和當前值
第二個,是初始值
8-Filter Arrays with filter
9-Sort Arrays with sort
a-b 是正序排
b-a 是逆序排
10-Reverse Arrays with reverse
11-Concatenate Arrays with concat
delimiter 分隔符號
12-Split Strings with split
13-Join Strings with join
Last updated
Was this helpful?