yzhanjsinterpreter
Version:
A JavaScript Interpreter Using JS itself. JavaScript 解释器,包含词法分析、语法解析和执行
30 lines • 727 B
JavaScript
module.exports = class {
constructor() {
this.properties = new Map()
this.prototype = null
}
#get(property) {
if (property.value !== void 0) return property.value
if (typeof property.get === 'function') return property.get()
return property
}
getProperty(key) {
let cur = this
while (cur !== null) {
const property = cur.properties.get(key)
if (property !== void 0) return this.#get(property)
cur = cur.prototype
}
return void 0
}
setProperty(key, { value, get, set, writable = true, enumerable = true, configurable = true }) {
this.properties.set(key, {
value,
get,
set,
writable,
enumerable,
configurable
})
}
}