1.0.13 • Published 7 years ago

assign-es6-class v1.0.13

Weekly downloads
4
License
MIT
Repository
github
Last release
7 years ago

assignEs6Class

This mini-library is meant to mimick the behavior of Object.assign for es6 classes. With Object.assign you can shallow merge object, but not their prototypes or attribute accessors. assignEs6Class will allow you to shallow merge the prototypes and properties of two instances of different classes.

import assignEs6Class from 'assign-es6-class';
// var assignEs6Class = require('assign-es6-class');

class Class1 {
  constructor() { 
    this._prop1 = 'property one';
  }
  get prop1(){
    return this._prop1;
  }
}
class Class2 {
  constructor() {
    this._prop1 = 'this prop will be replaced at assign';
    this._prop2 = 'property two';
  }
  get prop2() {
    return this._prop2;
  }
}

var c1 = new Class1();
var c2 = new Class2();

// first parameter is target class
var merged = assignEs6Class(c2,c1);

console.log(merged) // {_prop1:'property one', _prop2:'property two'}
console.log(merged.prop1,merged.prop2) //  "property one"  "property two"  
1.0.13

7 years ago

1.0.12

7 years ago

1.0.11

7 years ago

1.0.10

7 years ago

1.0.9

7 years ago

1.0.8

7 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago