Repository: gcanti/tcomb (js)

Issue:
strict Struct with additional methods throws a TypeError on updating
Test case:

```javascript
const t = require('tcomb');

const Rectangle = t.struct({
  width: t.Number,
  height: t.Number
}, {strict: true});

Rectangle.prototype.getArea = function () {
  return this.width * this.height;
};

let r = Rectangle({width: 10, height: 10});
Rectangle.update(r, {width: {$set: 20}});
```
throws:
```
TypeError: [tcomb] Invalid additional prop "getArea" supplied to Struct{width: Number, height: Number}
```

replacing `lib/assign.js` with `Object.assign` seems to fix the problem.

Pull request:
strict structs with additional methods should not throw on updating, …
…fix #267

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 7478e1f..a6dfda2 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -12,6 +12,11 @@
 **Note**: Gaps between patch versions are faulty/broken releases.
 **Note**: A feature tagged as Experimental is in a high state of flux, you're at risk of it changing without notice.
 
+# v3.2.16
+
+- **Bug Fix**
+  - strict structs with additional methods should not throw on updating, fix #267 (@gcanti)
+
 # v3.2.15
 
 - **New Feature**
diff --git a/lib/assign.js b/lib/assign.js
index cfef6ca..156a78b 100644
--- a/lib/assign.js
+++ b/lib/assign.js
@@ -1,8 +1,10 @@
 function assign(x, y) {
   for (var k in y) {
-    x[k] = y[k];
+    if (y.hasOwnProperty(k)) {
+      x[k] = y[k];
+    }
   }
   return x;
 }
 
-module.exports = assign;
\ No newline at end of file
+module.exports = assign;
diff --git a/package.json b/package.json
index 54abb2d..f7720ef 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
 {
   "name": "tcomb",
-  "version": "3.2.15",
+  "version": "3.2.16",
   "description": "Type checking and DDD for JavaScript",
   "main": "index.js",
   "typings": "index.d.ts",


Test patch:
diff --git a/test/update.js b/test/update.js
index e500294..021ebf6 100644
--- a/test/update.js
+++ b/test/update.js
@@ -14,6 +14,20 @@ describe('t.update(instance, patch)', function () {
     y: t.Number
   });
 
+  it('strict structs with additional methods should not throw on updating', function () {
+    var Rectangle = t.struct({
+      width: t.Number,
+      height: t.Number
+    }, {strict: true});
+
+    Rectangle.prototype.getArea = function () {
+      return this.width * this.height;
+    };
+
+    var r = Rectangle({width: 10, height: 10});
+    assert.equal(Rectangle.update(r, {width: {$set: 20}}).width, 20);
+  });
+
   it('should throw if patch is invalid', function () {
     throwsWithMessage(function () {
       t.update({});