0.0.23 • Published 10 years ago

get-constructors v0.0.23

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

get-constructors - npm

get an array of constructors (classes) for objects and classes.

supports Google Chrome, Mozilla Firefox, Microsoft ie11/10/9/8/7/6 and Node.js/io.js.

Japanese version/■日本語版はこちら■

INSTALL:

$ npm install get-constructors --save

or

http://lightspeedworks.github.io/get-constructors/get-constructors.js

<script src="http://lightspeedworks.github.io/get-constructors/get-constructors.js"></script>

PREPARE:

(function (constructors) {
  // you can use constructors
})(this.constructors || require('get-constructors'));

or

var constructors = this.constructors || require('get-constructors'));

USAGE:

function: constructors(object or Class/constructor)

var constructors = require('get-constructors');

constructors({});     // -> [Object]
constructors(Object); // -> [Object, Function.prototype]

constructors([]);     // -> [Array, Object]
constructors(Array);  // -> [Array, Function.prototype]

function Klass() {}
constructors(new Klass); // -> [Klass, Object]
constructors(Klass);     // -> [Klass, Function.prototype]

function SubKlass() {}
SubKlass.prototype = new Klass();
SubKlass.prototype.constructor = SubKlass;
SubKlass.super_ = Klass;

constructors(new SubKlass); // -> [SubKlass, Klass, Object]
constructors(SubKlass);     // -> [SubKlass, Klass, Function.prototype]

method: constructors.extendPrototype(ctor = Object)

Extends prototype method constructors and returns constructors.

Format

var constructors = require('get-constructors').extendPrototype();

({}).constructors()   // -> [Object]
Object.constructors() // -> [Object, Function.prototype]

[].constructors()     // -> [Array, Object]
Array.constructors()  // -> [Array, Function.prototype]

function Klass() {}
(new Klass).constructors() // -> [Klass, Object]
Klass.constructors()       // -> [Klass, Function.prototype]

function SubKlass() {}
SubKlass.prototype = new Klass();
SubKlass.prototype.constructor = SubKlass;
SubKlass.super_ = Klass;

(new SubKlass).constructors() // -> [SubKlass, Klass, Object]
SubKlass.constructors()       // -> [SubKlass, Klass, Function.prototype]

method: this.constructors()

Get an array of constructor functions (classes). (after: constructors.extendPrototype())

Format

var constructors = require('get-constructors').extendPrototype();

function BaseClass() {}
function MyClass() {}
MyClass.prototype = new BaseClass()
MyClass.prototype.constructor = MyClass;
MyClass.super_ = BaseClass;

var o1 = new MyClass();
console.log(o1.constructor === MyClass);   // -> true

var classes = o1.constructors();
console.log(classes[0] === MyClass);   // -> true
console.log(classes[1] === BaseClass); // -> true
console.log(classes[2] === Object);    // -> true

Returns

An array of constructor functions (classes).

method: Class.constructors()

Get an array of constructor functions (classes). (after: constructors.extendPrototype())

Format

var constructors = require('get-constructors').extendPrototype();

function BaseClass() {}
function MyClass() {}
MyClass.prototype = new BaseClass()
MyClass.prototype.constructor = MyClass;
MyClass.super_ = BaseClass;

var classes = MyClass.constructors();
console.log(classes[0] === MyClass);   // -> true
console.log(classes[1] === BaseClass); // -> true
console.log(classes[2] === Function.prototype); // -> true

Returns

An array of constructor functions (classes).

SEE ALSO:

base-class-extend - npm

LICENSE:

MIT License

0.0.23

10 years ago

0.0.22

10 years ago

0.0.21

10 years ago

0.0.20

10 years ago

0.0.19

10 years ago

0.0.18

10 years ago

0.0.17

10 years ago

0.0.16

10 years ago

0.0.15

10 years ago

0.0.14

10 years ago

0.0.13

10 years ago

0.0.12

10 years ago

0.0.11

10 years ago

0.0.10

10 years ago

0.0.9

10 years ago

0.0.8

10 years ago

0.0.7

10 years ago

0.0.6

10 years ago

0.0.5

10 years ago

0.0.4

10 years ago

0.0.3

10 years ago

0.0.2

10 years ago

0.0.1

10 years ago

0.0.0

10 years ago