代码心得

1.尽量物件导向化(例如在function内用  this.xxx = xxx)

2.变数尽量简洁、unused的删掉。

3.逻辑判断要清楚

4.应该做个双向绑定,例如可以输入生日,来测试情况

 

Vue.js

Vue.js給我的感覺是,將一組HTML物件化起來,定義它的方法、資料。

jQuery則是一開始使用 selector 找到物件,再定義要他們幹麻幹麻。

all Vue components are also Vue instances

Declarative vs Imperative Programming

https://codeburst.io/declarative-vs-imperative-programming-a8a7c93d9ad2

http://www.redotheweb.com/2015/09/18/declarative-imperative-js.html

https://msdn.microsoft.com/zh-tw/library/ff750239.aspx

https://msdn.microsoft.com/zh-tw/library/ff750239.aspx

https://stackoverflow.com/questions/33655534/difference-between-declarative-and-imperative-in-react-js

Default Parameters

Default Parameters:

If you are familiar with other programming languages like Ruby, Python then default parameters isn’t new to you.

Default parameters are parameters which are given by default while declaring a function. But it’s value can be changed when calling the function.

Example

let Func = (a, b = 10) => {
 return a + b; 
}
Func(20); // 20 + 10 = 30

In the above example, we are passing only one parameter. The function makes use of the default parameter and executes the function.

Consider another example:

Func(20, 50); // 20 + 50 = 70

In the above example, the function takes two parameters and the second parameter replaces the default parameter.

来源:https://codeburst.io/es6-tutorial-for-beginners-5f3c4e7960be

JavaScript let

if (true) {
 let a = 40;
 console.log(a); //40
}
console.log(a); // undefined

上面的范例,如果改成var的话,最下面一行的console.log(a); 却是可以获取到的(40)