So Answer / How to override and wrap a method from parent object?

See: http://stackoverflow.com/questions/20757377/javascript-how-to-override-and-wrap-a-method-from-parent-object

by KooiInc MeHere

HTML

<button id="my_o">my_o.work</button>
<button id="my_o2">my_o2.work</button>

JavaScript

replaceAlert();

$('#my_o,#my_o2').on('click', function(){
    alert({content: '<i>Working from instance '+this.id+'</i><br><br>'});
    window[this.id].work();
});


var o = {
     score: 5,
     work: function() {
                    alert({content: (this.testing || '') + ' <b>[prototype].work</b> here!<br>'+
                                    'Current instance score is '+this.score,append:1});                    
                    this.score = this.parent && this.parent.score || this.score;
           }
};

// my code
var cons = function (testing, score) {
     this.testing = testing || 'Hithere...';
     this.score = score || 10;
     this.parent = arguments.callee.prototype;
     this.parentwork = this.parent.work;
     this.work = function (st) {
         alert({content: 'Hello from <b>[instance].work</b><br><br>',append:1});
         this.parentwork.call(this);
         alert({content:'<br><b>[instance].work</b> is back:<br>work done: '+
                        'instance score is now '+this.score,append:1});
     };
 };
 cons.prototype = o;
 my_o = new cons('Hithere ',10);
 my_o2 = new cons('Hello ',12);


// Another way to show the result.
function replaceAlert() {
   $.fn.centerfix = function () {
          return this.css(
                   {
                     position: 'fixed',
                     top: Math.max(0, ($(window).height() - this.outerHeight()) / 2),
                     left: Math.max(0, ($(window).width() - this.outerWidth()) / 2)
                   }
                  );
    };    
    
      var cssClasses = {
          mBack: { // modal background layer
              left: 0,
              top: 0,
              right: 0,
              bottom: 0,
              position: 'fixed',
              zIndex: 2,
              opacity: 0.6,
              background: '#fff',
              filter: 'alpha(opacity=60)',
              '-ms-filter': 'alpha(opacity=60)',
              display: 'none'
          },
          mBox: { // modal box...