Chrome / Firefox中的Rect功能是什么? [英] What is Rect function in Chrome/Firefox for?

查看:84
本文介绍了Chrome / Firefox中的Rect功能是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我偶然发现了Firefox和Chrome(但不包含IE 10)中的 Rect()函数:

  type of Rect; //function
Rect; //函数Rect(){[native code]}

但是这个函数不能直接访问,也不作为构造函数:

  Rect(); // TypeError:非法构造函数
new Rect(); // TypeError:非法构造函数

这个函数的用途是什么?

解决方案

Rect 是一个在处理CSS <$时使用的文档对象模型(DOM)级别2样式规范 (例如浏览器中的Javascript DOM绑定)。



正如你注意到的,你不能调用它自己是一个构造函数,但实现这个接口的对象是由各种函数返回的。 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆