Lighter syntax for `create()`? #94

Open
aawwawa opened this Issue Sep 5, 2012 · 4 comments

Comments

Projects
None yet
4 participants
@aawwawa
Contributor

aawwawa commented Sep 5, 2012

Discussed this with @rvagg in IRC briefly. Here's the alias I would propose:

bonzo.new = function(tagname) { 
    return bonzo.create('<'+ tagname +'>');
};

It could obviously be implemented more performantly as a direct interface to the DOM, but I think it would be a more intuitive API. The current name create() evokes the native DOM's document.create(), which accepts a tag name, not a tag. So intuitively I always want to write bonzo.create('div'), and not bonzo.create('<div>'). That was perhaps the most recurring hitch in my adjustment to the API, FWIW.

@aawwawa

This comment has been minimized.

Show comment Hide comment
@aawwawa

aawwawa Sep 5, 2012

Contributor

Using new('div') would read better aloud, and make more intuitive sense as english. In my brief tests, having a member function of an object called new() does NOT conflict with the JS new keyword.

Contributor

aawwawa commented Sep 5, 2012

Using new('div') would read better aloud, and make more intuitive sense as english. In my brief tests, having a member function of an object called new() does NOT conflict with the JS new keyword.

@connor

This comment has been minimized.

Show comment Hide comment
@connor

connor Nov 25, 2012

Collaborator

im digging this. should we worry about new'ing multiple elements, at all? that might be dumb and complicating things that don't need to be. i'm all for this alias though.

Collaborator

connor commented Nov 25, 2012

im digging this. should we worry about new'ing multiple elements, at all? that might be dumb and complicating things that don't need to be. i'm all for this alias though.

@rvagg

This comment has been minimized.

Show comment Hide comment
@rvagg

rvagg Nov 25, 2012

Collaborator

It's really just an alias for document.createElement(tagname), the overhead of bonzo.create() can be completely avoided for this case. But because it's just duplicating an existing function that's available across browsers then perhaps this is just fluff?

Collaborator

rvagg commented Nov 25, 2012

It's really just an alias for document.createElement(tagname), the overhead of bonzo.create() can be completely avoided for this case. But because it's just duplicating an existing function that's available across browsers then perhaps this is just fluff?

@ded

This comment has been minimized.

Show comment Hide comment
@ded

ded Nov 25, 2012

Owner

We did this on Medium.com in an internal version of ender (just extending $).

$.createElement = function (tagName) {
  return $(document.createElement(tagName))
}

there were cases in the Editor where i'd need to create an Ender element out of a tag name. and it was more of a hassle to do this...

$('<' + tagName + '/>')
Owner

ded commented Nov 25, 2012

We did this on Medium.com in an internal version of ender (just extending $).

$.createElement = function (tagName) {
  return $(document.createElement(tagName))
}

there were cases in the Editor where i'd need to create an Ender element out of a tag name. and it was more of a hassle to do this...

$('<' + tagName + '/>')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment