// 內建方法返回新的 array (filter、map),他們是靠 constructor 屬性// add one more method to it (can do more)classPowerArrayextendsArray {isEmpty() {returnthis.length===0; }}let arr =newPowerArray(1,2,5,10,50);alert(arr.isEmpty()); // falselet filteredArr =arr.filter(item => item >=10);alert(filteredArr); // 10, 50alert(filteredArr.isEmpty()); // false// 從上面的例子當 arr.filter(),新的 array 是用 new PowerArray,我們可以用 PowerArray 的屬性arr.constructor=== PowerArray// 加上特殊靜態 getter Symbol.species,返回使用 filter、map 的 constructor。classPowerArrayextendsArray {isEmpty() {returnthis.length===0; }// built-in methods will use this as the constructorstaticget [Symbol.species]() {return Array; }}let arr =newPowerArray(1,2,5,10,50);alert(arr.isEmpty()); // false// filter creates new array using arr.constructor[Symbol.species] as constructorlet filteredArr =arr.filter(item => item >=10);// filteredArr is not PowerArray, but Arrayalert(filteredArr.isEmpty()); // Error: filteredArr.isEmpty is not a function