今日、私が行っている新しい SVG フレームワークに取り組んでいます。配列をサブクラス化してノードを操作しようとしています...そして数時間後にこのコードを終了します (私は Safari でのみテストしました):
customArray=function(){
// Do the thing
this.__proto__= Array.prototype;
// Add some prototypes to the main customArray
this.f1=function(){console.log(1)}; // f1 custom function
this.f2=function(){console.log(2)}; // f2 custom function
};
newCustomArray=new customArray();
newCustomArray.f3=function(){console.log(3)} // f3 function only for newCustomArray
console.log(newCustomArray instanceof Array); // true
console.log([] instanceof Array); // true
console.log("---------------------");
console.log(newCustomArray.f1); // function(){console.log(1)};
console.log(newCustomArray.f2); // function(){console.log(2)};
console.log(newCustomArray.f3); // function(){console.log(3)};
console.log([].f1); // undefined
console.log([].f2); // undefined
console.log([].f3); // undefined
console.log("---------------------");
console.log(newCustomArray.forEach); // Native function
console.log([].forEach); // Native function
私にとっては機能していますが、「システム」が言うように、プロトはどこにでもあるわけではありません。