Closed jamesshannon closed 11 years ago
Confirmed, I met the same problem.
In this case we have some problems with working with this
. A stupid workaround would be:
if this instanceof ModelClass
# for 'get'
else
# for 'toJSON'
My workaround has been to something like:
var channelTitle = (this.get) ? this.get('channelTitle') : this.channelTitle;
return channelTitle ? channelTitle + ' Videos' : ((this.get) ? this.get('snippet') : this.snippet).title;
My mutator's purpose is to return the channelTitle if it's been specified, otherwise return the snippet title, thus the two lines.
Good catch guys. I will try to add the fix this weekend (and release a new version).
Thank you.
I'm using the bleeding edge version. With Model#get(),
this
is the model. When using Model#toJSON(),this
is the JSON object.I did a
console.log(this)
in the mutator function and the following is the output: