base-class-extend
Advanced tools
Comparing version 0.0.13 to 0.0.14
@@ -43,3 +43,3 @@ // base-class-extend.js | ||
// Base.extend | ||
// Base.extend([name], [proto], [staticProps]) | ||
// Usage: | ||
@@ -143,3 +143,3 @@ // var SimpleClass = | ||
// Base.new or Base.create | ||
// Base.new(...args) or Base.create(...args) | ||
function Base_create() { | ||
@@ -166,7 +166,3 @@ if (this.prototype instanceof Array) { | ||
function assert(bool, msg) { | ||
if (!bool) throw new Error(msg); | ||
} | ||
// Base_addPrototype | ||
// Base.addPrototype(proto) | ||
function Base_addPrototype(proto) { | ||
@@ -178,8 +174,16 @@ setProto(proto, getProto(this)); | ||
// Base.extendPrototype([ctor = Function]) | ||
function Base_extendPrototype(ctor) { | ||
if (typeof ctor !== 'function') ctor = Function.prototype; | ||
ctor.extend = Base_extend; | ||
return this; | ||
} | ||
var Base = Base_extend('Base', | ||
{'private': Base_addPrototype, | ||
addPrototype : Base_addPrototype}, | ||
{extend: Base_extend, | ||
create: Base_create, | ||
'new': Base_create}); | ||
{'private': Base_addPrototype, | ||
addPrototype : Base_addPrototype}, | ||
{extend: Base_extend, | ||
create: Base_create, | ||
'new': Base_create, | ||
extendPrototype: Base_extendPrototype}); | ||
@@ -186,0 +190,0 @@ |
{ | ||
"name": "base-class-extend", | ||
"version": "0.0.13", | ||
"version": "0.0.14", | ||
"description": "Base Class constructor for easy class definition - supports getter/setter, inherit/extend Array Error or EventEmitter etc", | ||
"main": "lib/base-class-extend.js", | ||
"devDependencies": { | ||
"get-constructors": ">=0.0.3" | ||
"get-constructors": ">=0.0.4" | ||
}, | ||
@@ -9,0 +9,0 @@ "keywords": [ |
@@ -138,3 +138,6 @@ [base-class-extend](https://www.npmjs.org/package/base-class-extend) - npm | ||
```js | ||
Object.extend = BaseClass.extend; | ||
var BaseClass = require('base-class-extend').extendPrototype(Object); | ||
// or | ||
// Object.extend = BaseClass.extend; | ||
var SimpleClass = Object.extend('SimpleClass'); | ||
@@ -149,3 +152,6 @@ | ||
```js | ||
Array.extend = BaseClass.extend; | ||
var BaseClass = require('base-class-extend').extendPrototype(Array); | ||
// or | ||
// Array.extend = BaseClass.extend; | ||
var CustomArray = Array.extend('CustomArray'); | ||
@@ -163,3 +169,6 @@ | ||
```js | ||
Error.extend = BaseClass.extend; | ||
var BaseClass = require('base-class-extend').extendPrototype(Error); | ||
// or | ||
// Error.extend = BaseClass.extend; | ||
var CustomError = Error.extend('CustomError'); | ||
@@ -177,3 +186,7 @@ | ||
var EventEmitter = require('events').EventEmitter; | ||
EventEmitter.extend = BaseClass.extend; | ||
var BaseClass = require('base-class-extend').extendPrototype(EventEmitter); | ||
// or | ||
// EventEmitter.extend = BaseClass.extend; | ||
var CustomEventEmitter = EventEmitter.extend('CustomEventEmitter'); | ||
@@ -188,3 +201,5 @@ | ||
```js | ||
Function.prototype.extend = BaseClass.extend; | ||
var BaseClass = require('base-class-extend').extendPrototype(); | ||
// or | ||
// Function.prototype.extend = BaseClass.extend; | ||
@@ -208,9 +223,13 @@ var SimpleClass = Object.extend('SimpleClass'); | ||
// 'new'メソッドまたは'constructor'関数の中に定義すること | ||
var private1; | ||
this.addPrototype({ | ||
method1: function method1() { | ||
console.log(private1); }, | ||
get prop1() { return private1; }, | ||
set prop1(val) { private1 = val; }, | ||
}); | ||
{ | ||
constructor: function () { | ||
var private1; | ||
this.addPrototype({ | ||
method1: function method1() { | ||
console.log(private1); }, | ||
get prop1() { return private1; }, | ||
set prop1(val) { private1 = val; }, | ||
}); | ||
} | ||
} | ||
``` | ||
@@ -256,9 +275,13 @@ | ||
// 'new'メソッドまたは'constructor'関数の中に定義すること | ||
var private1; | ||
this.private({ | ||
method1: function method1() { | ||
console.log(private1); }, | ||
get prop1() { return private1; }, | ||
set prop1(val) { private1 = val; }, | ||
}); | ||
{ | ||
constructor: function () { | ||
var private1; | ||
this.private({ | ||
method1: function method1() { | ||
console.log(private1); }, | ||
get prop1() { return private1; }, | ||
set prop1(val) { private1 = val; }, | ||
}); | ||
} | ||
} | ||
``` | ||
@@ -265,0 +288,0 @@ |
@@ -137,3 +137,6 @@ [base-class-extend](https://www.npmjs.org/package/base-class-extend) - npm | ||
```js | ||
Object.extend = BaseClass.extend; | ||
var BaseClass = require('base-class-extend').extendPrototype(Object); | ||
// or | ||
// Object.extend = BaseClass.extend; | ||
var SimpleClass = Object.extend('SimpleClass'); | ||
@@ -148,3 +151,6 @@ | ||
```js | ||
Array.extend = BaseClass.extend; | ||
var BaseClass = require('base-class-extend').extendPrototype(Array); | ||
// or | ||
// Array.extend = BaseClass.extend; | ||
var CustomArray = Array.extend('CustomArray'); | ||
@@ -162,3 +168,6 @@ | ||
```js | ||
Error.extend = BaseClass.extend; | ||
var BaseClass = require('base-class-extend').extendPrototype(Error); | ||
// or | ||
// Error.extend = BaseClass.extend; | ||
var CustomError = Error.extend('CustomError'); | ||
@@ -176,3 +185,7 @@ | ||
var EventEmitter = require('events').EventEmitter; | ||
EventEmitter.extend = BaseClass.extend; | ||
var BaseClass = require('base-class-extend').extendPrototype(EventEmitter); | ||
// or | ||
// EventEmitter.extend = BaseClass.extend; | ||
var CustomEventEmitter = EventEmitter.extend('CustomEventEmitter'); | ||
@@ -187,3 +200,5 @@ | ||
```js | ||
Function.prototype.extend = BaseClass.extend; | ||
var BaseClass = require('base-class-extend').extendPrototype(); | ||
// or | ||
// Function.prototype.extend = BaseClass.extend; | ||
@@ -207,9 +222,13 @@ var SimpleClass = Object.extend('SimpleClass'); | ||
// defined in 'new' method or 'constructor' function | ||
var private1; | ||
this.addPrototype({ | ||
method1: function method1() { | ||
console.log(private1); }, | ||
get prop1() { return private1; }, | ||
set prop1(val) { private1 = val; }, | ||
}); | ||
{ | ||
constructor: function () { | ||
var private1; | ||
this.addPrototype({ | ||
method1: function method1() { | ||
console.log(private1); }, | ||
get prop1() { return private1; }, | ||
set prop1(val) { private1 = val; }, | ||
}); | ||
} | ||
} | ||
``` | ||
@@ -255,9 +274,13 @@ | ||
// defined in 'new' method or 'constructor' function | ||
var private1; | ||
this.private({ | ||
method1: function method1() { | ||
console.log(private1); }, | ||
get prop1() { return private1; }, | ||
set prop1(val) { private1 = val; }, | ||
}); | ||
{ | ||
constructor: function () { | ||
var private1; | ||
this.private({ | ||
method1: function method1() { | ||
console.log(private1); }, | ||
get prop1() { return private1; }, | ||
set prop1(val) { private1 = val; }, | ||
}); | ||
} | ||
} | ||
``` | ||
@@ -264,0 +287,0 @@ |
@@ -83,15 +83,15 @@ // animal-test.js | ||
console.log(); | ||
function mapName(elem) { return elem.name; } | ||
console.log('a1 ', a1.constructors.map(mapName).join(' < ')); | ||
console.log('Animal', Animal.constructors.map(mapName).join(' < ')); | ||
console.log('b1 ', b1.constructors.map(mapName).join(' < ')); | ||
console.log('Bear ', Bear.constructors.map(mapName).join(' < ')); | ||
console.log('c1 ', c1.constructors.map(mapName).join(' < ')); | ||
console.log('Cat ', Cat.constructors.map(mapName).join(' < ')); | ||
console.log('d1 ', d1.constructors.map(mapName).join(' < ')); | ||
console.log('Dog ', Dog.constructors.map(mapName).join(' < ')); | ||
function nm(elem) { return elem.name; } | ||
console.log(Animal.constructors.map(nm).join(' < '), ': Animal'); | ||
console.log(a1 .constructors.map(nm).join(' < '), ': a1'); | ||
console.log(Bear .constructors.map(nm).join(' < '), ': Bear'); | ||
console.log(b1 .constructors.map(nm).join(' < '), ': b1'); | ||
console.log(Cat .constructors.map(nm).join(' < '), ': Cat'); | ||
console.log(c1 .constructors.map(nm).join(' < '), ': c1'); | ||
console.log(Dog .constructors.map(nm).join(' < '), ': Dog'); | ||
console.log(d1 .constructors.map(nm).join(' < '), ': d1'); | ||
var Klass = BaseClass.extend.call(Object, 'Klass'); | ||
var k1 = new Klass(); | ||
console.log('k1 ', k1.constructors.map(mapName).join(' < ')); | ||
console.log('Klass ', Klass.constructors.map(mapName).join(' < ')); | ||
console.log(Klass .constructors.map(nm).join(' < '), ': Klass'); | ||
console.log(k1 .constructors.map(nm).join(' < '), ': k1'); |
@@ -61,7 +61,7 @@ // private-test.js | ||
console.log(); | ||
function mapName(elem) { return elem.name; } | ||
console.log('p1 ', p1.constructors.map(mapName).join(' < ')); | ||
console.log('p2 ', p2.constructors.map(mapName).join(' < ')); | ||
console.log('p3 ', p3.constructors.map(mapName).join(' < ')); | ||
console.log('p4 ', p4.constructors.map(mapName).join(' < ')); | ||
console.log('PrivateClass1', PrivateClass1.constructors.map(mapName).join(' < ')); | ||
function nm(elem) { return elem.name; } | ||
console.log(PrivateClass1.constructors.map(nm).join(' < '), ': PrivateClass1'); | ||
console.log(p1 .constructors.map(nm).join(' < '), ': p1'); | ||
console.log(p2 .constructors.map(nm).join(' < '), ': p2'); | ||
console.log(p3 .constructors.map(nm).join(' < '), ': p3'); | ||
console.log(p4 .constructors.map(nm).join(' < '), ': p4'); |
@@ -38,4 +38,4 @@ // quick.js | ||
console.log(); | ||
function mapName(elem) { return elem.name; } | ||
console.log('myObj ', myObj.constructors.map(mapName).join(' < ')); | ||
console.log('MyClass', MyClass.constructors.map(mapName).join(' < ')); | ||
function nm(elem) { return elem.name; } | ||
console.log(MyClass.constructors.map(nm).join(' < '), ': MyClass'); | ||
console.log(myObj.constructors.map(nm).join(' < '), ': myObj'); |
@@ -77,6 +77,6 @@ // vector-private-test.js | ||
console.log(); | ||
function mapName(elem) { return elem.name; } | ||
console.log('v2 ', v2.constructors.map(mapName).join(' < ')); | ||
console.log('Vector2D', Vector2D.constructors.map(mapName).join(' < ')); | ||
console.log('v3 ', v3.constructors.map(mapName).join(' < ')); | ||
console.log('Vector3D', Vector3D.constructors.map(mapName).join(' < ')); | ||
function nm(elem) { return elem.name; } | ||
console.log(Vector2D.constructors.map(nm).join(' < '), ': Vector2D'); | ||
console.log(v2 .constructors.map(nm).join(' < '), ': v2'); | ||
console.log(Vector3D.constructors.map(nm).join(' < '), ': Vector3D'); | ||
console.log(v3 .constructors.map(nm).join(' < '), ': v3'); |
@@ -66,6 +66,6 @@ // vector-test.js | ||
console.log(); | ||
function mapName(elem) { return elem.name; } | ||
console.log('v2 ', v2.constructors.map(mapName).join(' < ')); | ||
console.log('Vector2D', Vector2D.constructors.map(mapName).join(' < ')); | ||
console.log('v3 ', v3.constructors.map(mapName).join(' < ')); | ||
console.log('Vector3D', Vector3D.constructors.map(mapName).join(' < ')); | ||
function nm(elem) { return elem.name; } | ||
console.log(Vector2D.constructors.map(nm).join(' < '), ': Vector2D'); | ||
console.log(v2 .constructors.map(nm).join(' < '), ': v2'); | ||
console.log(Vector3D.constructors.map(nm).join(' < '), ': Vector3D'); | ||
console.log(v3 .constructors.map(nm).join(' < '), ': v3'); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
453558
26
811
446