成人无码视频,亚洲精品久久久久av无码,午夜精品久久久久久毛片,亚洲 中文字幕 日韩 无码

資訊專欄INFORMATION COLUMN

從Array到Null

ccj659 / 571人閱讀

摘要:問題等方法前面不寫定義一個數(shù)組,并打印確實沒有等方法問題既然是由構(gòu)造函數(shù)構(gòu)造的實例,為什么沒有繼承的方法靜態(tài)方法只能通過類構(gòu)造函數(shù)本身調(diào)用不能通過實例調(diào)用定義靜態(tài)方法我是方法我是方法之前定義靜態(tài)方法我是方法實例報錯再回頭看問題方法的調(diào)用方式

Array

問題1:isArray、from、of等方法前面不寫prototype?
let a1 = [1, 2, 3]
console.dir(a1)
// 定義一個數(shù)組a1,并打印a1
// 確實沒有isArray等方法

問題2:a1既然是由構(gòu)造函數(shù)Array()構(gòu)造的實例,為什么沒有繼承Array的方法?
// 靜態(tài)方法
// 只能通過 類/構(gòu)造函數(shù) 本身調(diào)用
// 不能通過 實例 調(diào)用
class Array1 {
  static isArray() {  // ES6定義靜態(tài)方法
    console.log("我是isArray方法")
  }
  map() {
    console.log("我是map方法")
  }
}
Array1.forEach = function() {  // ES6之前定義靜態(tài)方法
  console.log("我是forEach方法")
}
let a1 = new Array1()
console.log("實例a1", a1)
// a1.isArray()
// 報錯: a1.isArray is not a function

再回頭看 問題1
// 方法的調(diào)用方式
let a2 = [1, 2, 3]
a2.push(4)
Array.isArray(a2)

// 構(gòu)造函數(shù)prototype 里的方法會被繼承到實例里面
// Array的prototype 里的方法會被繼承到實例a2里面
a2.__proto__ === Array.prototype
a2.__proto__.constructor === Array

// 1、構(gòu)造函數(shù)為Array
// 2、原型對象為Array.prototype, 所有由Array生成的實例都會繼承里面的方法
// 3、a2.__proto__ 指向原型對象
// 4、a2._proto__.constructor指向構(gòu)造函數(shù)
Null
a2.__proto__.constructor // ? Array() { [native code] }
a2.__proto__.constructor === Array
// a2的構(gòu)造函數(shù)為Array

Array.__proto__.constructor // ? Function() { [native code] }
Array.__proto__.constructor === Function
// Array的構(gòu)造函數(shù)為Function

Function.__proto__.constructor // ? Function() { [native code] }
Function.__proto__.constructor === Function
// Function的構(gòu)造函數(shù)為Function

Function.prototype.__proto__.constructor
Function.prototype.__proto__.constructor === Object
// ? Object() { [native code] }
// Function

Object.prototype.__proto__.constructor 
// Cannot read property "constructor" of null
Object.prototype.__proto__ === null

文章版權(quán)歸作者所有,未經(jīng)允許請勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。

轉(zhuǎn)載請注明本文地址:http://m.hztianpu.com/yun/110051.html

相關(guān)文章

  • 讀lodash源碼之slice看稀疏數(shù)組與密集數(shù)組

    摘要:例如其中的為,但是數(shù)組中沒有元素,是稀疏數(shù)組而每個位置都是有元素的,雖然每個元素都為,為密集數(shù)組。那稀疏數(shù)組和密集數(shù)組有什么區(qū)別呢在中最主要考慮的是兩者在迭代器中的表現(xiàn)。截取并返回新數(shù)組為新數(shù)組容器。 卑鄙是卑鄙者的通行證,高尚是高尚者的墓志銘。 ——北島《回答》 看北島就是從這兩句詩開始的,高尚者已死,只剩卑鄙者在世間橫行。 本文為讀 lodash 源碼的第一篇,后續(xù)文章會更新到...

    lijy91 評論0 收藏0
  • Laravel 管道流原理

    摘要:管道流原理強烈依賴函數(shù),我們先來了解下函數(shù)的使用。第二次迭代時,的值為上述返回的閉包偽代碼,的值為,返回一個閉包,當我們執(zhí)行這個閉包時,滿足,得到結(jié)果。自定義中間件為的管道流核心類在的方法中,為上述的閉包,為要通過的中間件數(shù)組,為對象。 Laravel管道流原理強烈依賴array_reduce函數(shù),我們先來了解下array_reduce函數(shù)的使用。 原標題PHP 內(nèi)置函數(shù) array_...

    Mr_zhang 評論0 收藏0
  • 簡單總結(jié)一下JS的Array對象

    摘要:簡單總結(jié)一下的對象屬性數(shù)組指定創(chuàng)建一個數(shù)組的函數(shù)。方法數(shù)組返回一個迭代器,它返回數(shù)組的鍵值對。方法數(shù)組返回滿足回調(diào)函數(shù)中指定的測試條件的第一個數(shù)組元素的索引值。該回調(diào)函數(shù)的返回值為累積結(jié)果,并且此返回值在下一次調(diào)用該回調(diào)函數(shù)時作為參數(shù)提供。 簡單總結(jié)一下JS的Array對象 constructor 屬性(數(shù)組) 指定創(chuàng)建一個數(shù)組的函數(shù)。該屬性可用于判斷某個對象是否為數(shù)組與arr ins...

    malakashi 評論0 收藏0
  • es6常用數(shù)組操作及技巧匯總

    摘要:檢測數(shù)組或者檢測對象的原型鏈是否指向構(gòu)造函數(shù)的對象或者終極大招注意不可以用此方法檢查常用方法合并多個數(shù)組,返回合并后的新數(shù)組,原數(shù)組沒有變化。返回值是由被刪除的元素組成的一個數(shù)組。 定義數(shù)組 const array = [1, 2, 3]; 或者 const array = new Array(); array[0] = 1; 建議盡量使用第一種形式定義數(shù)組,采用new的形式在大量的數(shù)...

    Noodles 評論0 收藏0

發(fā)表評論

0條評論

閱讀需要支付1元查看
<