ded / bonzo

library agnostic, extensible DOM utility
Other
1.32k stars 137 forks source link

Feature- MooTools-esque create element function? #12

Closed beatgammit closed 13 years ago

beatgammit commented 13 years ago

Just an idea, how do you feel about a create function that accepts a properties?

Instead of MooTools' Element syntax, there could be something like this:

var elem = $.create('canvas', {
    width: 400,
    height: 300
});

OR

var template = $("#myCanvas");
var elem = $.create(template, {
    width: 400,
    height: 300
});

I think that passing in this style of syntax really makes sense, and is more javascript-y than having to construct an HTML string.

My use case is canvas; reason being, canvas' height/width can't be changed on the fly, so they have to be recreated every time the width and height change (like on a mobile device when the orientation changes).

I like this syntax a lot better than the existing jQuery-style syntax. What do you think? Is there already a way to do this that I didn't notice?

ded commented 13 years ago

i'd rather not break the existing interface since many people are use to it. However I think — as a completely separate utility (outside of Bonzo) there is merit in this. I have a keen like for Closure's goog.dom.createDom method which has the ability to pass in a dom reference to another (for nesting purposes). Doing this outside of Bonzo also keeps this library lighter — and allows you to fully do it right in a separately maintained project.