咱們幾乎天天都要用到push方法,咱們真的明白在調用push方法後,瀏覽是怎麼運行這個方法?es6
push原生方法的長度屬性爲1數組
NOTE: push方法被刻意設計爲一種通用的方法;它並不要求this對象是一個數組對象。所以它能使用特定方法被其餘對象調用。函數
var obj={
addElem : function addElem(elem){
[].push.call(this,elem);
//Array.prototype.push.call(this,elem);
}
}
obj.addElem('1');
obj.addElem('2');
console.log(obj.length) //result is 2
複製代碼
咱們來看看具體有哪些更新:this
es6內部抽象程度更高,更加規範,調用了不少方法來處理不一樣的過程,那讓咱們來了解研究這些方法究竟是幹什麼的。spa
Object抽象方法它能夠將參數轉變爲對象類型的值。prototype
arguments type | result |
---|---|
Completion Record | If argument is an abrupt completion, return argument. Otherwise return ToObject(argument.[[value]]). |
Undefined | Throw a TypeError exception. |
Null | Throw a TypeError exception. |
Boolean | 返回新的Boolean對象 |
Number | 返回新的Number對象 |
String | 返回新的String對象 |
Symbol | 返回新的Symbol對象 |
Object | 返回對象 |
其中Boolean,Number,String,Symbol,參數類型爲這些時,返回的新對象都是用internal slot(暫且翻譯爲內部插槽從新設置的對象),可是何爲internal slot,還不理解,理解再來敘說。翻譯
完成時 類型被用做記錄運行時,值傳遞的狀態,例如一些跳出局部控制的狀態(break, continue, return and throw)。設計
Field | Value | Meaning |
---|---|---|
[[type]] | One of normal, break, continue, return, or throw | 其中某一種狀態已經被調用 |
[[value]] | Undefined, Null, Boolean, String, Symbol, Number, and Object中的一種,或者empty | 值已經產生 |
[[target]] | any ECMAScript string or empty | The target label for directed control transfers. |
重點:abrupt completion(忽然完成) 是指在[[Type]]之中除了nomral以外的狀態code