-
?
1.關于typeof null,機器碼后三位000(與對象完全一樣)
2. typeof function 為什么是function而不是object,在于是否存在call方法
查看全部 -
// 什么是棧:計算機為原始類型開辟的一塊內存空間 string number ...
// 什么是堆:計算機為引用類型開辟的一塊內存空間 object
var a = 'MOOC';
var b = a;
console.log(a, b); // MOOC MOOC2
var c = {key: 1};
var d = c;
d.key = 2;
console.log(c, d); // 2, 2
// ['MOOC', 'MOOC2']
// c d ['x00000018', 'x00000018'] -> { {key: 1} }
// c d x00000018 -> {key: 2}
查看全部 -
// instanceof 檢測 bool: true false
// A instanceof B
console.log([] instanceof? Array); // true
console.log({} instanceof? Object); // true
console.log(new Date instanceof? Date); // true
function Person(){};
console.log(new Person() instanceof? Person); // true
console.log([]?instanceof? Object); // true
console.log(new Date instanceof? Object); // true
console.log(new Person() instanceof? Object); // true
//?instanceof 原型鏈 A?instanceof B true, B?instanceof C true
// 兒子 爸爸 爺爺
if(typeof(val) !== undefined) {}
console.log(Object.prototype.toString.call('1')); // string
console.log(Object.prototype.toString.call([])); // Array
查看全部 -
// typeof 檢測 返回的是對應的數據類型
console.log(typeof(123)); // number
console.log(typeof(true)); // boolean
console.log(typeof('MOOC')); // string
console.log(typeof(undefined)); // undefined
console.log(typeof(null)); // object 為什么不null
// 計算機typeof 返回的數據類型 機器碼 01011: 000 => object
// null 000000...000 => object
// js bug?
console.log(typeof([])); // object? // 引用
console.log(typeof(new Date())); // object
console.log(typeof({})); // object
console.log(typeof(function(){})); // function
console.log(typeof(Array)); // function 為什么不是object
// typeof 引用類型 object: object function
// object 定義一個[[call]] 如果已經定義了call方法就是 function 不是 object
var str = 'MOOC';
console.log(typeof(str)); // string
var str1 = new String('MOOC'); // 實例化后的對象
console.log(str1); // {} key : value 0:M 1:O ....
console.log(typeof(str1)); //?object
查看全部 -
淺拷貝兩種方式:遍歷 和 Object.create()
查看全部 -
^qUxJg$c43abd01a5fabbba66466a22476d2957b84506584
查看全部 -
console.log(Object.prototype.toString.call('1') console.log(Object.prototype.toString.call('[]')
查看全部 -
todo 沒看懂
查看全部 -
包裝對象:String Number Boolean
查看全部 -
JS中this的用法
代指當前調用這個對象
4中綁定規則:默認綁定、隱式綁定、顯示綁定、new綁定。優先級從低到高。
改變this指向:call? apply? bind
手寫一個bind方法
查看全部 -
js中New的執行過程有哪幾步
實例化對象
共4步驟:
創建一個新的對象obj:var obj = new Object()
把obj的proto指向構造函數的prototype對象 實現繼承:obj.__proto__ = Fn.prototype
將步驟1新創建的對象obj作為this的上下文:var result = Fn.call(obj)
返回創建的對象obj(如果該函數沒有返回對象,則返回this)
if( typeof result === 'object' ){
? ? return result? //func = result
}else{
? ? return obj????//func = obj
}
查看全部 -
function對象call、apply、bind
????Function.apply ( obj, args )//args為數組
????Function.call ( obj, args )//args為單個參數
一、apply方法
apply()方法調用一個函數,其具有一個指定的this值,以及作為一個數組(或類數組對象)提供的參數。
apply方法能劫持另一個對象的方法,繼承另外一個對象的屬性
function.apply(obj, args)方法能接受兩個參數
obj:這個對象將代替function類里this對象
args:這個是數組,他將作為參數傳給funcrion(args--->arguments)
二、call方法
call方法與apply作用相同,唯一區別是第二個args參數
call:單個參數傳入,apply:以數組形式傳入
三、bind方法
bind:類似于call 但是與其不用的是call調用之后可以立即執行,但是bind需要用一個變量進行接收之后再執行。
查看全部 -
js中閉包的概念:
是引用了自由變量的函數這個被引用的自由變量將和這個函數一同存在,即使已經離開了,創造它的環境也不例外。
另一種說法認為閉包是由函數和其相關的引用環境組合而成,實現信息的駐留(信息的保持,引用在空間不銷毀)。
++的解釋:加號在前取新值,加號在后取舊值
可以使用立即執行函數來實現閉包
閉包的缺點:閉包導致內存會駐留,如果是大量對象的閉包環境會造成內存泄漏
查看全部 -
js重載的概念
在程序中可以定義相同名字,不同參數的形式的不同函數。
函數在調用的函數的時候,自動識別不同參數對應的函數,實現了相同函數名不同的函數調用
javascript本身沒有重載的,但是可以通過arguments來實現函數重載
查看全部 -
????
原型鏈
查看全部
舉報