Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

inherits-ex

Package Overview
Dependencies
Maintainers
1
Versions
51
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

inherits-ex - npm Package Compare versions

Comparing version 1.2.3 to 1.3.0

Gruntfile.js

48

lib/mixin.js

@@ -53,3 +53,3 @@ var inheritsDirectly = require('./inheritsDirectly');

*
mixin the exists method: the new mixin method will oerwrite the old one.
mixin the exists method: the new mixin method will overwrite the old one.

@@ -169,8 +169,47 @@ ```coffee

function _clone(dest, src, ctor, filter) {
// filter = _getFilterFunc(filter);
var names = getOwnPropertyNames(src);
for (var i = 0; i < names.length; i++ ) {
var k = names[i];
// if (k === 'Class' || k === 'constructor') continue;
var value = filter(k, src[k]);
if (value !== void 0) dest[k] = value;
}
}
function cloneCtor(dest, src, ctor, filter) {
var filterFn = function (name, value) {
for (var n of [ 'length', 'name', 'arguments', 'caller', 'prototype' ]) {
if (n === name) {
value = void 0;
break;
}
if (value !== void 0) value = filter(name, value);
}
return value;
}
_clone(dest, src, ctor, filterFn);
}
//clone src(superCtor) to dest(MixinCtor)
function clonePrototype(dest, src, ctor, filter) {
filter = _getFilterFunc(filter);
// filter = _getFilterFunc(filter);
var filterFn = function (name, value) {
for (var n of [ 'Class', 'constructor' ]) {
if (n === name) {
value = void 0;
break;
}
if (value !== void 0) value = filter(name, value);
}
return value;
}
var sp = src.prototype;
var dp = dest.prototype;
_clone(dp, sp, ctor, filterFn);
/*
var names = getOwnPropertyNames(sp);

@@ -231,2 +270,3 @@

}
*/
}

@@ -271,3 +311,5 @@

mixinCtors.push(superCtor);//quickly check in isMixinedFrom.
clonePrototype(mixinCtor, superCtor, ctor, options && options.filter);
var filterFn = _getFilterFunc(options && options.filter);
cloneCtor(mixinCtor, superCtor, ctor, filterFn);
clonePrototype(mixinCtor, superCtor, ctor, filterFn);
inheritsDirectly(ctor, mixinCtor);

@@ -274,0 +316,0 @@ result = true;

12

package.json

@@ -5,3 +5,3 @@ {

"homepage": "https://github.com/snowyu/inherits-ex.js",
"version": "1.2.3",
"version": "1.3.0",
"author": {

@@ -42,4 +42,5 @@ "name": "Riceball LEE",

"chai": "~1.10.0",
"coffee-coverage": "^0.6.2",
"grunt": "*",
"coffee-coverage": "^2.0.1",
"coffee-script": "^1.12.7",
"grunt": "^1.3.0",
"grunt-contrib-clean": "*",

@@ -51,4 +52,3 @@ "grunt-contrib-coffee": "^1.0.0",

"grunt-newer": "*",
"grunt-release": "*",
"istanbul": "^0.3.17",
"istanbul": "^0.4.5",
"mocha": "~2.1.0",

@@ -68,3 +68,3 @@ "pre-commit": "1.1.3",

"dependencies": {
"xtend": "^4.0.0"
"xtend": "^4.0.2"
},

@@ -71,0 +71,0 @@ "browser": {

@@ -145,2 +145,4 @@ ### Inherits-Ex [![npm](https://img.shields.io/npm/v/inherits-ex.svg)](https://npmjs.org/package/inherits-ex)

Mixin the methods and properties of the SuperCtor: Clone(Copy) all `superCtor`'s properties(methods) to ctor.
* options:

@@ -162,5 +164,5 @@ * filter: defaults to 0.

+ duplication mixin or inheritance check
+ **NOTE:**:the methods in mixins using `super()` will jump to the old class(not stay on the class).
* The mixined properties(methods) are cloned(copied) from superCtors
* duplication mixin or inheritance check
* **NOTE:**:the methods in mixins using `super()` will jump to the old class(not stay on the class).
* The mixined properties(methods) are cloned(copied) from superCtors(includes the static members)
* The all mixined properties(methods) are the first parent's ctor(`MixinCtor_`)

@@ -209,2 +211,4 @@ * eg, `ctor -> MixinCtor_ -> original parents`

check the ctor whether is mixined from superCtor.
```js

@@ -214,2 +218,18 @@ var isMixinedFrom = require('inherits-ex/lib/isMixinedFrom')

## createCtor(name, args, body)
Create a constructor(class) dynamically.
* `name`(*string*): the class name
* `args`(*any[]*): the optional constructor's args.
* `body`(*string*): the optional constructor function body.
```js
const createClass = require('inherits-ex/lib/createCtor')
const MyClass = createClass('MyClass', ['a', 'b'], 'this.sum = a + b');
var my = new MyClass(1, 2);
console.log(my.sum);
```
## createObject(ctor, args...)

@@ -221,2 +241,9 @@

var createObject = require('inherits-ex/lib/createObject')
class MyClass {
constructor(a,b) {
this.sum = a + b;
}
}
var o = creatObject(MyClass, 1, 2)
console.log(o.sum)
```

@@ -223,0 +250,0 @@

@@ -53,3 +53,3 @@ var inheritsDirectly = require('./inheritsDirectly');

*
mixin the exists method: the new mixin method will oerwrite the old one.
mixin the exists method: the new mixin method will overwrite the old one.

@@ -169,8 +169,47 @@ ```coffee

function _clone(dest, src, ctor, filter) {
// filter = _getFilterFunc(filter);
var names = getOwnPropertyNames(src);
for (var i = 0; i < names.length; i++ ) {
var k = names[i];
// if (k === 'Class' || k === 'constructor') continue;
var value = filter(k, src[k]);
if (value !== void 0) dest[k] = value;
}
}
function cloneCtor(dest, src, ctor, filter) {
var filterFn = function (name, value) {
for (var n of [ 'length', 'name', 'arguments', 'caller', 'prototype' ]) {
if (n === name) {
value = void 0;
break;
}
if (value !== void 0) value = filter(name, value);
}
return value;
}
_clone(dest, src, ctor, filterFn);
}
//clone src(superCtor) to dest(MixinCtor)
function clonePrototype(dest, src, ctor, filter) {
filter = _getFilterFunc(filter);
// filter = _getFilterFunc(filter);
var filterFn = function (name, value) {
for (var n of [ 'Class', 'constructor' ]) {
if (n === name) {
value = void 0;
break;
}
if (value !== void 0) value = filter(name, value);
}
return value;
}
var sp = src.prototype;
var dp = dest.prototype;
_clone(dp, sp, ctor, filterFn);
/*
var names = getOwnPropertyNames(sp);

@@ -231,2 +270,3 @@

}
*/
}

@@ -271,3 +311,5 @@

mixinCtors.push(superCtor);//quickly check in isMixinedFrom.
clonePrototype(mixinCtor, superCtor, ctor, options && options.filter);
var filterFn = _getFilterFunc(options && options.filter);
cloneCtor(mixinCtor, superCtor, ctor, filterFn);
clonePrototype(mixinCtor, superCtor, ctor, filterFn);
inheritsDirectly(ctor, mixinCtor);

@@ -274,0 +316,0 @@ result = true;

@@ -1,17 +0,17 @@

chai = require('chai')
sinon = require('sinon')
sinonChai = require('sinon-chai')
assert = chai.assert
expect = chai.expect
should = chai.should()
var chai = require('chai')
var sinon = require('sinon')
var sinonChai = require('sinon-chai')
var assert = chai.assert
var expect = chai.expect
var should = chai.should()
inherits = require('../src/inherits')
inheritsDirectly= require('../src/inheritsDirectly')
inheritsObject = require('../src/inheritsObject')
mixin = require('../src/mixin')
isInheritedFrom = require('../src/isInheritedFrom')
isMixinedFrom = require('../src/isMixinedFrom')
createObject = require('../src/createObject')
createObjectWith= require('../src/createObjectWith')
getProtoChain = require('../src/getProtoChain')
var inherits = require('../src/inherits')
var inheritsDirectly= require('../src/inheritsDirectly')
var inheritsObject = require('../src/inheritsObject')
var mixin = require('../src/mixin')
var isInheritedFrom = require('../src/isInheritedFrom')
var isMixinedFrom = require('../src/isMixinedFrom')
var createObject = require('../src/createObject')
var createObjectWith= require('../src/createObjectWith')
var getProtoChain = require('../src/getProtoChain')

@@ -30,2 +30,5 @@ log = console.log.bind(console)

class A1 extends A{
mo() {
mCallOrder.push('A1mo')
}
m1(){

@@ -40,2 +43,3 @@ mCallOrder.push('A1m1');

}
A1.prototype.prop1 = 2;
class B {

@@ -57,5 +61,34 @@ m(){

o = new B1()
expect(o.prop1).to.be.equal(2)
// o.should.have.property('prop1', 2)
o.m("a", 12) // call chain: B1::m -> A1::m -> A::m
mCallOrder.should.be.deep.equal ['B1', 'A1', 'A']
mCallOrder = []
o.mo()
mCallOrder.should.be.deep.equal ['A1mo']
mCallOrder = []
o.m1()
mCallOrder.should.be.deep.equal ['A1sm', 'Asm']
mCallOrder = []
})
it("test mixin static with super", function(){
let mCallOrder = [];
class A {
static sm() {
mCallOrder.push('Asm')
}
}
class A1 extends A{
static sm() {
mCallOrder.push('A1sm')
super.sm()
}
}
class B1 {
}
mixin(B1, A1).should.be.equal(true, 'mixin');
B1.sm()
mCallOrder.should.be.deep.equal ['A1sm', 'A']
})
})

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc