Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/wookieb/es5-extend
Simple helper to extend object (even native) with es5-ext functions
https://github.com/wookieb/es5-extend
Last synced: about 1 month ago
JSON representation
Simple helper to extend object (even native) with es5-ext functions
- Host: GitHub
- URL: https://github.com/wookieb/es5-extend
- Owner: wookieb
- Created: 2014-05-21T19:05:49.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2014-05-26T09:43:08.000Z (over 10 years ago)
- Last Synced: 2024-02-05T23:03:53.752Z (11 months ago)
- Language: JavaScript
- Size: 141 KB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# es5-extend
[![Build Status](https://travis-ci.org/wookieb/es5-extend.png)](https://travis-ci.org/wookieb/es5-extend)Simple helper for extending native or other objects with es5-ext functions
## Installation
```
npm install es5-extend
```## Usage
Extending all native objects (for given context)
```
var extend = require('es5-extend');
extend([methods [, customDescriptor] ])
```* *context* - global object with native objects
* methods - array of methods to insert into native object
* customDescriptor - custom options for property descriptorExtending 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.```javascript
// for node.js
require('es5-extend').call(global);// for browser
require('es5-extend').call(window);
```### Extending native objects with subset of methods
```javascript
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
```javascript
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
```javascript
require('es5-extend').function(['pluck']);'pluck' in Function; // true
```### Extending specific non-native object
```javascript
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
```javascript
require('es5-extend').function(['pluck'], {configurable: true);Object.getOwnPropertyDescriptor(Function, 'pluck').configurable; // true
```