javascript - undefined is not a function in backbone -
i using backbone , workflow.js extension set flow of application. have next backbone model
var invoicemodel = backbone.model.extend({ workflow: { initial: 'draft', events: [ { name: 'issue', from: 'draft', to: 'issued' }, { name: 'payout', from: 'issued', to: 'paid' }, { name: 'cancel', from: 'draft', to: 'canceled' }, { name: 'cancel', from: 'issued', to: 'canceled' } ] }, initialize: function () { _.extend(this, new backbone.workflow(this, { attrname: 'status' })); } });
i using above model below
var invoicemodel = new invoicemodel(); console.log(invoicemodel.get('status')); invoicemodel.triggerevent('issue'); // uncaught typeerror: undefined not function
somehow when utilize triggerevent()
function returns undefined not function
. why , how can prepare error?
update
here fiddle
the method triggerevent()
hides in prototype of workflow
object.
_.extend()
copies object's own properties without properties prototype.
your illustration work with:
class="lang-js prettyprint-override">initialize: function () { _.extend(this, (new backbone.workflow(this, { attrname: 'status' })).__proto__, new backbone.workflow(this, { attrname: 'status' })); }
as can see, explicitly added prototype extend chain.
know it's inelegant solution. though didn't find improve 1 yet, hope explain problem.
this works:
class="lang-js prettyprint-override">var workflow = new backbone.workflow(this, { attrname: 'status' }); _.extend(this, workflow); $.extend(this, workflow);
here underscore copies workflow
s own properties (model
) , jquery deep-copies properties prototype.
javascript jquery backbone.js workflow
No comments:
Post a Comment