queryObjects
是Chrome 62新增的一個Command Line API
。webpack
官網這樣介紹該APIweb
A new API for querying heap objects
Call queryObjects(Constructor) from the Console to return an array of objects that were created with the specified constructor. For example:chrome
- queryObjects(Promise). Returns all Promises.
- queryObjects(HTMLElement). Returns all HTML elements.
- queryObjects(foo), where foo is a function name. Returns all objects that were instantiated via new foo().
- The scope of queryObjects() is the currently-selected execution context in the Console. See Selecting execution context.
queryObjects(Constructor)
能夠去查找currently-selected execution context
中指定Constructor
的全部實例
。異步
execution context
execution context
是代碼的執行環境,默認爲top
。其餘的execution context
能夠來自內嵌的iframe、Extensions、Service WorkerConstructor
queryObjects
接受的第一個參數的值類型能夠是函數也能夠是對象,當是函數時,是使用函數的prototype屬性值做爲查找的原型對象
。queryObjects(RegExp)
和queryObjects(RegExp.prototype)
最終獲得的結果是相同的。實例
queryObjects
從當前execution context
中的全部對象中過濾出原型鏈中包含指定原型對象
的對象。 因此有如下狀況。queryObjects(Object)
的結果會包含queryObjects(Array)
的結果async
.shoplist
對應的Vue組件實例。queryObjects(Object)
獲取全部的對象,Vue組件實例一定包含在其中,將異步結果值存爲全局變量temp1
。temp1.filter(a=>a.shopList)
過濾出結果。RegExp
、Date
對象,queryObjects(RegExp);
queryObjects(Date);
複製代碼
Generator 函數
,async 函數
queryObjects(Function) // 將異步結果值存爲全局變量temp1
----------
temp1.filter(item => {
return foo[Symbol.toStringTag] === 'GeneratorFunction'
});
temp1.filter(item => {
return foo[Symbol.toStringTag] === 'AsyncFunction'
});
複製代碼
queryObjects(Object) // 將異步結果值存爲全局變量temp1
----------
temp1.filter(a=>a.__esModule)
複製代碼