0.1.1 • Published 11 years ago

es5-extend v0.1.1

Weekly downloads
2
License
MIT
Repository
github
Last release
11 years ago

es5-extend

Build Status

Simple helper for extending native or other objects with es5-ext functions

Installation

es5-extend does not bundle es5-ext package itself so you need to do it manually

npm install es5-ext
npm install es5-extend

Usage

Extending all native objects (for given context)

extend([methods [, customDescriptor] ])
  • context - global object with native objects
  • methods - array of methods to insert into native object
  • customDescriptor - custom options for property descriptor

Extending specific object

extend.array([nativeObject [, methods [, customDescriptor ] ] ]);
extend.boolean([nativeObject [, methods [, customDescriptor ] ] ]);
extend.date([nativeObject [, methods [, customDescriptor ] ] ]);
extend.error([nativeObject [, methods [, customDescriptor ] ] ]);
extend.function([nativeObject [, methods [, customDescriptor ] ] ]);
extend.math([nativeObject [, methods [, customDescriptor ] ] ]);
extend.number([nativeObject [, methods [, customDescriptor ] ] ]);
extend.object([nativeObject [, methods [, customDescriptor ] ] ]);
extend.regExp([nativeObject [, methods [, customDescriptor ] ] ]);
extend.string([nativeObject [, methods [, customDescriptor ] ] ]);
  • nativeObject - object to extend
  • methods - array of methods to insert into native object
  • customDescriptor - custom options for property descriptor

Extending all native objects with all methods in es5-ext

Please use it wisely.

// for node.js
require('es5-extend').call(global);

// for browser
require('es5-extend').call(window);

Extending native objects with subset of methods

require('es5-extend').call(global, ['pluck', 'contains']);

'pluck' in global.Function; // true
'contains' in String.prototype; // true
'contains' in Array.prototype; // true

Extending specific native object

require('es5-extend').array();
// same as
require('es5-extend').array(Array);

'contains' in Array.prototype; // true
'contains' in String.prototype; //

Extending specific native object with subset of methods

require('es5-extend').function(['pluck']);

'pluck' in Function; // true

Extending specific non-native object

var CustomKlazz = function() {
    // ...
};
CustomKlazz.prototype = new Array();
extend.array(CustomKlazz, ['keys']);

'keys' in Array.prototype; // false
'keys' in CustomKlazz.prototype; // true

Extending specific native object with custom property descriptor

require('es5-extend').function(['pluck'], {configurable: true);

Object.getOwnPropertyDescriptor(Function, 'pluck').configurable; // true