Reputation: 386
I am new to Backbone
, so can't understand what I am doing wrong. What I need is to override saveCompat (media-models.js
line 310
, WP 3.9.1
). I am trying to do it same way I have overridden some media views
wp.media.model.Attachment = wp.media.model.Attachment.extend({
saveCompat: function( data, options ) {
some code here...
}
});
But it doesn't work for me. Native WordPress saveCompat
is executed. At the same time the very same idea is perfectly working for wp.media.view.AttachmentCompat
for example
wp.media.view.AttachmentCompat = wp.media.view.AttachmentCompat.extend({
save: function( event ) {
some code here...
}
});
Thanks in advance!
Upvotes: 1
Views: 561
Reputation: 21
Using _.extend
removes the ability to call the super class implementation of methods. The proper (or at least a working) way to do it is to use Backbone's extend
method and then overwrite the prototype in wp.media.model.Attachment
like this:
var MediaCreditAttachmentModel = wp.media.model.Attachment.extend( {
saveCompat: function( data, options ) {
...
}
} );
wp.media.model.Attachment.prototype = MediaCreditAttachmentModel.prototype;
Upvotes: 1
Reputation: 386
I figured it out. The correct way to extend it is:
_.extend( wp.media.model.Attachment.prototype, {
saveCompat: function( data, options ) {
some code here...
}
});
Upvotes: 2