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!
I figured it out. The correct way to extend it is:
_.extend( wp.media.model.Attachment.prototype, {
saveCompat: function( data, options ) {
some code here...
}
});
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;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.