Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is Rect function in Chrome/Firefox for?

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?

like image 544
Pavlo Avatar asked Sep 15 '13 16:09

Pavlo


1 Answers

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());
like image 92
nmaier Avatar answered Oct 11 '22 08:10

nmaier