重新定义数组原型以创建指向oldarrprototypeconstoldarrprototype=array.prototype的新对象; constarrproto=object.create (oldarrprototype ); ['push '、' pop '、' shift '、' unshift ' ].foreach (method name={ arr proto [ method name ]=function ) ]更新. arguments ) )如果observer的target是数组,则将其原型更改为上面创建的arrproto,并在其中重写方法的if(array.isarray(target ) ) { tarray
这将污染全球阵列原型。