JSFiddle - React, Tailwind, and code Playground

by 1UnitedPower

JavaScript

function ObservedArray () {
    Array.call( this );
}

ObservedArray.prototype = Object.create( Array.prototype, {
    push : {
        value : function( value ){
           console.log('beforePush');
           Array.prototype.push.call( this, value);
           console.log('afterPush');
        }
    }    
});

var myObservedArray = new ObservedArray();

myObservedArray[0] = 'foo';
myObservedArray[1] = 'bar';
myObservedArray.push('baz');
console.log( myObservedArray );