nl_tokens: Array handling -------------- Arrays are special because unlike other property types they have standard mutator functions ( push / pop / splice / etc . ) and it s desirable to trigger a change notification whenever one of those mutator functions is invoked . Traditionally Knockout handles this by putting special versions of push / pop / etc . on observable arrays that mutate the underlying array and then trigger a notification . That approach doesn t work for Knockout - ES5 because properties now return the underlying arrays so the mutator runs in the context of the underlying array not any particular observable : // Operates on the underlying array value myModel . someCollection . push ( New value ) ; To solve this Knockout - ES5 detects array values and modifies them as follows : 1 . Associates a hidden subscribable with each array instance that it encounters 2 . Intercepts standard mutators ( push / pop / etc . ) and makes them trigger the subscribable Then for model properties whose values are arrays the property s underlying observable subscribes to the array subscribable so it can trigger a change notification after mutation . After each array mutation fires a notification on the given subscribable
pl_tokens: function wrapStandardArrayMutators ( array , subscribable , signal ) { var fnNames = [ 'pop' , 'push' , 'reverse' , 'shift' , 'sort' , 'splice' , 'unshift' ] ; fnNames . forEach ( function ( fnName ) { var origMutator = array [ fnName ] ; array [ fnName ] = function ( ) { var result = origMutator . apply ( this , arguments ) ; if ( signal . pause !== true ) { subscribable . notifySubscribers ( this ) ; } return <mask> ; } ; } ) ; }