Firebolt is a framework that extends native and host JavaScript objects. It has been said many times that doing this is "evil", and this was quite true up until recently. Nowadays, modern browsers are much more amenable to prototype-extending, enabling Firebolt to be a reliable and stable framework.

Below are the specific ways in which prototype-extending can cause problems and how Firebolt overcomes these problems.


1. Future-proofing

Problems:

New ECMAScript specifications may implement a new method with the same name as a library that has already implemented it and but with functional differences.

Solution:

ECMAScript specs take a long time from when they are first written up to when they are implemented so it is easy to use names that don't conflict with future specs or change the name of something if it is going to conflict (as there will be lots of time for developers to accept the name change) or even change a method so that it is in line with the future specification.

Another option would be to use names that are very unlikely to be used in a future ECMAScript or DOM specification. Of course, this may mean that the names you come up with will be somewhat obscure. How obscure the name is should depend on how many developers are working with the code. For one developer, you can be as obscure as you want, whereas large teams should choose more conventional names.

Firebolt's Stance:

Firebolt uses fairly descriptive names except for when the point of the function is to reduce the amount of code that needs to be written (like how Element.prototype.QSA is an alias for Element.prototype.querySelectorAll). Currently, Firebolt is future-proofed against ECMAScript 6 and what currently exists of ECMAScript 7 as well as what is currently in the WHATWG DOM Living Standard.


2. Enumerable Properties

Problems:

Extending a prototype can expose the extensions as enumerable properties (i.e. on an Array), which can cause problems with for...in loops as seen in the example below.


for (var i in []) {
  console.log(i); // Never gets called

Array.prototype.remove = function() { /* ... */ };
for (var i in []) {
  console.log(i); // -> "remove"
}
    

Solution:

Use Object.defineProperty() to extend prototypes without making the new property enumerable. This is perfectly fine if you do not need to support IE8 or below.

Firebolt's Stance:

Firebolt only supports IE9 and up so Firebolt uses Object.defineProperty() to define non-enumerable properties when necessary.


3. Property Shadowing

Problems:

Extending Object.prototype will mean that all objects will automatically have that property (which may be enumerated) and the property may be overwritten and cause confusion. Example:


Object.prototype.doSomething = function() { /* ... */ };

var obj1 = {
  a: false,
  b: true
};
var obj2 = {
  doSomething: false,
  doSomethingElse: true
};

obj1.doSomething(); // Works
obj2.doSomething(); // TypeError: boolean is not a function
    

Solution:

Just don't extend Object.prototype.

Or use Object.defineProperty() to make sure the new property is not enumerable and be mindful when defining an object with a property that has the same name as the extension.

Firebolt's Stance:

Firebolt simply never extends Object.prototype.


4. Collisions

Problems:

Two developers (or libraries) may extend a prototype in two different places with the same property name but with conflicting implementations.

Solution:

Individual developers should never extend prototypes when working with other developers. It is perfectly fine to use (or make) a prototype-extending library with a well-documented API so everyone working on the same project knows what methods there are and how they work. You should also only ever include one library that extends prototypes in a web page unless you are absolutely certain there will be no collisions.

Firebolt's Stance:

Firebolt is a framework with a fully-documented API. When using a prototype-extending framework, you should expect the documented extensions to exist and function as documented. You should also expect that those are the only extensions that have been made.


5. Extending Host (DOM) Objects

Problems:

kangax wrote a blog post on the problems with extending DOM objects: http://perfectionkills.com/whats-wrong-with-extending-the-dom/

Solution:

The DOM specification has been much improved since that blog post was written (now on to Level 5, which is HTML5) and modern browsers (since IE9) implement the DOM spec fairly consistently. This means that there are no more problems with performance or the IE DOM (mostly) and there are far fewer browser bugs that need to be taken into consideration. There is also a working future specification that we can look at to avoid possible future collisions (the DOM Living Standard).

Firebolt's Stance:

Firebolt only supports IE9 and above and tries it's best to avoid collisions with current DOM properties (there is currently only one collision that is clearly documented), so the problems mentioned in kangax's post do not apply to Firebolt.