why is Model.init implemented like this?

52 views
Skip to first unread message

andreas schmid

unread,
May 17, 2012, 12:59:34 PM5/17/12
to spi...@googlegroups.com

as difined here:

Module.init is implemented like:

Module.init = Controller.init = Model.init = (a1, a2, a3, a4, a5) ->
 
new this(a1, a2, a3, a4, a5)

why is it like this? why define 5 attributes and not use attrs... so attributes are not fixed to 5....

new this(attrs...)

Alex MacCaw

unread,
May 17, 2012, 4:50:29 PM5/17/12
to spi...@googlegroups.com
You can't do that with JavaScript unfortunately. 
--
Alex MacCaw

+12147175129
@maccman

http://alexmaccaw.co.uk

Andreas

unread,
May 17, 2012, 10:17:33 PM5/17/12
to spi...@googlegroups.com
this is taken from spine.coffee so yes you can:


which translates into
var __slice = [].slice;

Module.init = Controller.init = Model.init = function() {
 
var args;
  args
= 1 <= arguments.length ? __slice.call(arguments, 0) : [];
 
return (function(func, args, ctor) {
    ctor
.prototype = func.prototype;
   
var child = new ctor, result = func.apply(child, args), t = typeof result;
   
return t == "object" || t == "function" ? result || child : child;
 
})(this, args, function(){});
};

Message has been deleted

Alex MacCaw

unread,
May 18, 2012, 4:16:31 AM5/18/12
to spi...@googlegroups.com
Yes, you're right - I take that back, sorry! 

However, that's an awful lot of code :) - I'm actually taking out .init() in the next version of Spine anyhow. 

Andreas

unread,
May 18, 2012, 9:02:38 AM5/18/12
to spi...@googlegroups.com
trust me i trust you! :)

and i admit i don't know too much about js. this question was more an didactical one.

Alex MacCaw

unread,
May 18, 2012, 10:31:21 AM5/18/12
to spi...@googlegroups.com
Yes, a but too much hubris on my part there :)
Reply all
Reply to author
Forward
0 new messages