navigator若是找不到能夠可設置爲空對象node
var navigator={};
能夠使用jsdom模塊瀏覽器
瀏覽器裏表示window,nodejs中表示objectdom
obj.x //寫死代碼裏 obj["x"] //能夠動態調用屬性,[]內是字符串
var xhr = new XMLHttpRequest(); //建立xhr對象 xhr.open("GET", url, true); //請求數據 用GET方法 異步獲取 xhr.onreadystatechange = function() { //一個事件能夠獲取請求以後的東西 if (xhr.readyState == 4 && xhr.status == 200) { console.log(xhr.responseText); } };
函數是Function的實例異步
語法: new Function(arg1, arg2........argN, body); 1,Function中的參數所有是字符串。 2,構造函數的做用是將參數鏈接起來構成函數。 * 若是參數只有一個便是表示函數體。 * 若是參數多個,最後一個爲函數體,前面的全是表示函數參數。 * 若是沒有參數,即建立空函數。
如下兩種建立函數示例的方法是同樣的模塊化
function foo(num) { console.log(num) } 等價於 var func = new Function("num","console.log(num);"); //參數都是字符串,最後一個參數是函數體的內容。
分別經過如下方式調用函數
foo(5) func(5)
define(['myLib'], function(myLib) { function foo() { myLib.somefunction() } return { foo: foo }; });
嚴格模式中 全部的變量都要聲明(在非嚴格模式中,給未聲明的變量賦值,是給全局對象window對象添加一個屬性)
嚴格模式中 函數(不是方法)中的this值爲undefined,非嚴格模式指代全局對着(window)ui
var a; 1==1 && a=2
表示若是前面條件1==1爲true,則a=2。this