Giter Club home page Giter Club logo

dom-elements's People

Contributors

barberboy avatar bloodyowl avatar jonathanong avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dom-elements's Issues

Naming confusion

Hi! This is a great project!

@annevk and I are the authors of the Elements proposal, with @annevk being the the author of the DOM spec.

We were a bit saddened that you decided to name this project after, and include references to, the W3C's fork of the DOM Standard. The actual DOM Standard is maintained by @annevk at the WHATWG; the W3C copies it into their URL-space for intellectual property reasons, and renames it "DOM 4".

I know renaming kind of sucks, but would you be willing to set the record straight here? At least with the correct links to the source material, instead of the fork.

array subclass

the issue

the actual issue is that Elements' behaviour deviates from Array:

var elements = new Elements()
elements[4] = 1
elements.length // 0
elements.length = 0
elements[4] // 1

the workarouds

__proto__

in the browsers supporting the non-standard __proto__, we can do this :

function Elements(){
  var elements = Array.apply(null, arguments)
  elements.__proto__ = Elements.prototype
  return elements
}

Elements.prototype = []
Elements.prototype.constructor = Elements

Elements.prototype.query = function(){
  // …
}

var elements = new Elements()
elements instanceof Elements // true
elements instanceof Array // true
Array.prototype.foo = "bar"
elements.foo // "bar"

which makes a proper subclass as :

  • there is prototypal inheritance
  • we have the array length and index behaviour

direct extension

function Elements(){
  var elements = Array.apply(null, arguments)
      , key
  for(key in Elements.prototype) {
    if(!Elements.prototype.hasOwnProperty(key)){
      continue
    }
    elements[key] = Elements.prototype[key]
  }
  return elements
}

Elements.prototype = []
Elements.prototype.constructor = Elements

Elements.prototype.query = function(){
  // …
}

var elements = new Elements()
elements instanceof Elements // false
elements instanceof Array // true
Array.prototype.foo = "bar"
elements.foo // "bar"
  • there is no prototypal inheritance for Elements.prototype, adding a method to it will not work for the instances that have been created before
  • we have the array length and index behaviour though

iframe array

var Elements = IframeArray

Elements.prototype.query = function(){
  // …
}

var elements = new Elements()
elements instanceof Elements // true
elements instanceof Array // false
Array.prototype.foo = "bar"
elements.foo // void 0
  • makes possible inheritance from Elements.prototype in older browsers
  • doesn't inherit from current windows's array

doesn't match the specification

results from query and queryAll should be relative to the element, don't they ?

<div id="foo">
  <strong></strong>
</div>
document.getElementById("foo").query("div strong")
// -> should return `null`
document.getElementById("foo").query("strong")
// -> should return the element

The constructor should be exposed

That way you can do things like new Elements(document.query('#a'), document.query('#b')).queryAll('.c'). Similar to jQuery's $('#a').add($('#b')).find('.c'). Basically any situation where you might programmatically construct a set of elements.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.