Pav*_*vlo 13 javascript function
我偶然发现Rect()了Firefox和Chrome(但不是IE 10)中的功能:
typeof Rect; // "function"
Rect; // function Rect() { [native code] }
Run Code Online (Sandbox Code Playgroud)
但是这个函数既不能直接访问,也不能作为构造函数访问:
Rect(); // TypeError: Illegal constructor
new Rect(); // TypeError: Illegal constructor
Run Code Online (Sandbox Code Playgroud)
这个功能的目的是什么?
nma*_*ier 11
这Rect是在文档对象模型(DOM)级别2样式规范中定义的接口,用于rect()在DOM绑定中处理CSS 时(例如浏览器中的Javascript DOM绑定).
正如您所注意到的那样,您自己无法将其称为构造函数,但实现此接口的对象将由各种函数返回,例如.getRectValue():
function doSomething(v) {
if (v instanceof Rect) {
...
}
else {
...
}
}
doSomething(window.getComputedStyle(elem, null).
getPropertyCSSValue(styleProp).getRectValue());
Run Code Online (Sandbox Code Playgroud)