Skip to content

Latest commit

 

History

History
18 lines (17 loc) · 486 Bytes

function9.md

File metadata and controls

18 lines (17 loc) · 486 Bytes

不要写全局函数

Bad logo

	Array.prototype.diff = function diff(comparisonArray) {
	  const hash = new Set(comparisonArray);
	  return this.filter(elem => !hash.has(elem));
	};

Good logo

	class SuperArray extends Array {
	  diff(comparisonArray) {
	    const hash = new Set(comparisonArray);
	    return this.filter(elem => !hash.has(elem));
	  }
	}