Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>To elaborate a little and add some more relevant info (it took me a little while to figure out the accepted answer, and I'm clearly not alone looking at the other answers, also, the accepted answer only works for <em>one type</em> of Raphael object: it solves the original question, this is a more complete resource).</p> <hr> <h2>Detecting Raphael elements</h2> <p>Using <code>x.constructor.prototype == Raphael.el</code>, you're taking <code>x</code>, the variable that might be a Raphael <strong><em>element</em></strong> (circle, path etc - <strong>not</strong> a Raphael <code>set</code> or <code>paper</code> object) and comparing the prototype of the function that constructed it with the prototype for Raphael elements in Raphael itself (Raphael is a function object, el is a defined property of it).</p> <p>This works, but it also won't find raphael objects based on different prototypes to Raphael.el, like sets and paper objects: </p> <hr> <h2>Detecting Raphael sets</h2> <p>If you wanted to test if something was a Raphael set, the set prototype is in <code>Raphael.st</code> so you could test if a variable is a Raphael set using: </p> <p><code>someSet.constructor.prototype == Raphael.st</code></p> <hr> <h2>Detecting Raphael paper objects</h2> <p>As for the equivalent for sniffing Raphael <strong>paper</strong> objects, since they are created using <code>Raphael()</code> function, you can use: </p> <p><code>paper.constructor.prototype == Raphael.prototype</code></p> <hr> <p>The above three are basically the same as... </p> <p><code>someSet.constructor.prototype == paper.circle().constructor.prototype</code> </p> <p>...or... </p> <p><code>someSet.constructor.prototype == paper.set().constructor.prototype</code></p> <p>...or... </p> <p><code>someSet.constructor.prototype == Raphael().constructor.prototype</code></p> <p>...but without <em>actually running those functions</em>, so avoiding wasted processing (and avoiding Raphael() complaining that it hasn't been passed an ID).</p> <hr> <h2>Detecting sub-types of object (e.g. rectangle, circle...)</h2> <p>None of the above works for subtypes of Raphael elements - e.g. if you compare a circle with <code>R.rect().constructor.prototype</code>, it returns <strong><code>true</code></strong>.</p> <p>This is because both circles and rectangles are made using the <em>element</em> prototype defined in <code>Raphael.el</code>. For these, however, Raphael makes it easy:</p> <p><code>someRectangle.type == "rect"</code></p> <p><code>someCircle.type == "circle"</code></p> <p>...etc..</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload