Chrome / Firefox中的Rect功能是什么? [英] What is Rect function in Chrome/Firefox for?
问题描述
我偶然发现了Firefox和Chrome(但不包含IE 10)中的 Rect()
函数:
type of Rect; //function
Rect; //函数Rect(){[native code]}
但是这个函数不能直接访问,也不作为构造函数:
Rect(); // TypeError:非法构造函数
new Rect(); // TypeError:非法构造函数
这个函数的用途是什么?
正如你注意到的,你不能调用它自己是一个构造函数,但实现这个接口的对象是由各种函数返回的。 eg .getRectValue()
:
函数doSomething(v ){
if(v instance of Rect){
...
}
else {
...
}
}
doSomething(window.getComputedStyle(elem,null)。
getPropertyCSSValue(styleProp).getRectValue());
I've stumbled upon Rect()
function, which is present in both Firefox and Chrome (but not IE 10):
typeof Rect; // "function"
Rect; // function Rect() { [native code] }
But this function isn't accessible neither directly, nor as a constructor:
Rect(); // TypeError: Illegal constructor
new Rect(); // TypeError: Illegal constructor
What is the purpose of this function?
The Rect
is an interface defined in Document Object Model (DOM) Level 2 Style Specification to be used when dealing with CSS rect()
in DOM bindings (such as the Javascript DOM bindings in a browser).
As you noticed you cannot call it as a constructor yourself, but objects implementing this interface are returned by various functions e.g. .getRectValue()
:
function doSomething(v) {
if (v instanceof Rect) {
...
}
else {
...
}
}
doSomething(window.getComputedStyle(elem, null).
getPropertyCSSValue(styleProp).getRectValue());
这篇关于Chrome / Firefox中的Rect功能是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!