調用Number()
當有運算符(加減乘除,求餘)時,會調用Number()轉爲數字再運算,除了 加 當 有字符串時就變身成拼接
Boolean();
String();
typeof()string返回的類型
在<script>裏面的代碼,進行預編譯,將變量聲明,,函數聲明提升在邏輯的前面;執行代碼時在GO(即window對象)中取出值,
var a = 1;
function text(){}
例如 Go{
a : undefined;
text : function(){}
}
當遇到函數的執行時(執行前一刻),也會進行預編譯,和上面差很少,,1將聲明變量,形參賦值爲undefined,2 將形參值傳入 3 聲明方法
AO = (Active Object)
{
a : undefined;
text : function(){
}
ps:變量名和函數名相同時會覆蓋
function text(a,b,c){
}
就是找規律好比 ,,求階乘 求n的階乘,,
1 寫出通式 f(n) = n * f(n-1); 2 找終止條件
function jiecheng(n) {
if( n == 1){
return 1;
}
return n*jiecheng(n-1);
}
|| 尋找爲真的表達式,,將值返回,不會再執行後面的表達式
&& 尋找假的表達式 將值返回,,不會再執行後面的表達式
一、在函數聲明後,,就會有 a[[scope]]生成,做用域鏈 例如數組
二、函數執行時,生成Ao
function a(){
function b(){
}
}
定義時 A scope chain{0 : GO,}
執行時 A scope chain{0: ao ;1 : GO,}
執行完畢時,銷燬引用,回到定義時狀態
定義時 B scope chain{0 : A - ao ; 1 : GO} 它的出生在A中,,定義時,,就把A的執行Ao拿到本身B鏈中
執行時 B scope chain{0 : B - a0; 1 : A - a0;; 2 : GO}
執行完畢時,銷燬引用,回到定義時狀態
+ - ! 能夠把函數聲明變爲當即執行,執行後就失去了銷燬數組
//當即執行函數,,只執行一次,,執行完就會銷燬 // 能夠有返回值和
() 爲執行符號,,能執行表達式
(function() {} () );推薦寫法
(function () {})(); var a = (function (a,b){ console.log("888888888888888") return a*b; }(1,2)) console.log(a)
// 聖盃模式,,繼承 Father.prototype.sex = "女"; function Father() { } function Son() { } var inherit = (function (){ var F = function(){}; return function(Target,Origin) { F.prototype = Origin.prototype; Target.prototype = new F(); //prototype 是個對象,,直接賦值,指向的是同一個內存,,改變一個就會都會改變,new F(); 每次返回都是新的對象 防止父類被篡改 Target.prototype.constuctor = Target; Target.prototype.super = Origin.prototype; } }()); inherit(Son,Father); var son = new Son(); var father = new Father();