In Rails, you have this API for creating a model:
User.createIn Tower, we were/are also using that method (as of April 30, 2012):
App.User.createHowever, in JavaScript, create is used differently by convention. It is used to instantiate a new object, similar to Ruby's Object.new:
Object.create # plain JavaScript
Ember.Object.create # Ember.js way of instantiating objectsCurrently in Tower, since we are integrating Ember.js, we have to alias the Ember.Object.create method, to something like this:
Tower.Model.build
Tower.Model.new # or Tower.Model["new"] in plain JavaScriptWhile I like the elegance of Tower.Model.new in CoffeeScript, it's not a clean solution in JavaScript.
I propose we just stray from the Rails API here and adhere to the JavaScript conventions, using Tower.Model.create to "construct" a new model.
Then the question is, what do we call the method for "inserting" a model to the database (formerly .create)? How about just .insert.
App.User.insert(email: 'example@localhost.com')What are your thoughts?
.append ? Or does that get too confusing when dealing with client-side code because of appending things to the DOM?