Skip to content

Latest commit

 

History

History
27 lines (20 loc) · 370 Bytes

do-not-extend-built-in-prototypes.md

File metadata and controls

27 lines (20 loc) · 370 Bytes

Do not extend built-in prototypes

Do not extend the prototype of native JavaScript objects.

[JavaScript][../js/do-not-extend-built-in-prototypes.js]

Right:

var a = [];
if (!a.length) {
  console.log('winning');
}

Wrong:

Array.prototype.empty = function() {
  return !this.length;
}

var a = [];
if (a.empty()) {
  console.log('losing');
}