我想獲得HTML元素的所有屬性,樣式,事件和方法的列表。瀏覽器中是否有反射API?瀏覽器中的JavaScript是否有反射機制?
我正在尋找這樣的事情:
var button = new HTMLButtonElement();
var className = document.getQualifiedClassName(button); // "HTMLButtonElement"
var definition = document.getDefinition(className); // HTMLButtonElement reference
var instance = document.getInstance(definition); // instance of HTMLButtonElement
var properties = document.getProperties(button); // properties of HTMLButtonElement
var methods = document.getMethods(button); // methods of HTMLButtonElement
var styles = document.getStyles(button); // styles applicable to HTMLButtonElement
var events = document.getEvents(button); // events on HTMLButtonElement
var inheritance = document.getInheritance(button); // HTMLButtonElement > HTMLElement
編輯:
這是基於ActionScript3的調用得到什麼我在尋找:
var objectInformation = document.describeType(button) // metadata
這可能讓它更清楚我想要在JavaScript中做什麼。
背景
假設我想將代碼完整添加到HTML代碼編輯器。當用戶將他們的光標放在div元素旁邊並啓動代碼完成時,我想向他們展示代碼完成時彈出的所有事件和屬性和樣式。當他們在JavaScript中輸入時,我想自動完成所有可用的方法。當他們開始輸入樣式對象時,我想提供一個樣式列表。
如果我得到一個對象或標籤名稱,我需要能夠顯示代碼完成的所有元數據。在很多語言中都有API來執行此操作。