原生JS基礎知識(九)

2021-10-02 21:21:39 字數 783 閱讀 1939

我的github

官方的兩種寫法

(function () {}()); // 推薦
(function () {})();
tips : 只有表示式才能被執行符號()執行

function demo() ();
var demo = function () ()
tips : 能被執行符號執行的表示式的名字會被自動忽略 , 以下寫法實際上就是立即執行函式

var test = function () ();

console.log(test); // undefined

+ function test() ();

console.log(test); // test is not defined

- function test() ();

console.log(test); // test is not defined

! function test() ();

console.log(test); // test is not defined

原生JS基礎知識(五)

我的github 函式封裝 減少 耦合 抽象規則 引數 引數js形參和實參天生不定參 function test 1 a,b,c test 1 1,2 實參列表arguments 類陣列 function test 2 a,b,c console.log arguments.length 4 tes...

原生JS基礎知識(十二)

我的github in 判斷是否能在物件本身及其整條原型鏈上找到該屬性 var arr arr.name haha console.log name in arr true,name in arr console.log slice in arr true,slice in arr.proto co...

python基礎知識(九)

遞迴函式 條件 1 函式自己呼叫自己 2 函式呼叫必須有退出 eg def hanshu x print x if x 1 return hanshu x 1 print hanshu 4 結果為 階乘eg 求10!def jiecheng x if x 1 return 1 a jiecheng ...