RE: Elements (extends Array)

From: Boris Zbarsky [mailto:bzbarsky@MIT.EDU]


> On 8/7/13 11:48 PM, Domenic Denicola wrote:
> > I believe the intent here is to allocate an object that acts exactly like the
> one that you get when doing `class Elements extends Array { ... }` in ES6.
> 
> I guess the question is whether that object would have any special Elements-
> associated magic, right?
> 
> Put another way, would methods off of Elements.prototype be generic or
> only work on "Elements" objects?

They should be generic, I think. In particular, I believe `Elements.prototype.selectAll.call(normalArrayOfElements, "selector")` should work, at least assuming `selectAll`s implementation is anything like it is in the Gist. (It may not be, e.g. because it's easier to optimize something that behaves less generically. But the general idea of getting all the elements that match an absolutized version of `selector`, then stuffing them into the object created via `this.constructor`—for whichever `this` you're being called with now—seems sensible.)

Received on Thursday, 8 August 2013 04:06:18 UTC