元素原型作为字符串

Element prototype as string

本文关键字:字符串 原型 元素      更新时间:2023-09-26

如果可以创建字符串形式的Element.prototype

例如:

而不是:

Element.prototype.height = function() { return this.offsetHeight; };

写这样的东西:

Element.prototype.height = Element.offsetHeight;

你可以尝试这样的事情:

Element.prototype = {
        get height( ):{   return this.offsetHeight;   }
        constructor : Element
};

用法:

new Element().height    //without parenthesis

有关,请参阅对象获取器/设置器。