From 8856c6fda51c702a5fec664bfd426b39e7d830e3 Mon Sep 17 00:00:00 2001 From: Mikael Karon Date: Thu, 22 Sep 2016 03:23:02 +0200 Subject: [PATCH] feat(prototype): added support for setting protype (#3) If you want to set the _actual_ `prototype` you can now do so by providing a spec with the `prototype` key provided to `mu-create/prototype`: ```javascript var p = { "log": function(m) { console.log(m); } }; var C = create(proto, { "prototype": p }); var c = C(); c.log("testing"); // logs "testing" ``` --- prototype.js | 7 ++++++- tests/create.js | 19 ++++++++++++++----- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/prototype.js b/prototype.js index b6b2e41..7b867ca 100644 --- a/prototype.js +++ b/prototype.js @@ -10,6 +10,11 @@ } })([], this, function() { return function(result, data) { - result.prototype[data.key] = data.value; + if (data.key === "prototype") { + result.prototype = data.value; + } + else { + result.prototype[data.key] = data.value; + } } }); diff --git a/tests/create.js b/tests/create.js index 8e94ed9..9773834 100644 --- a/tests/create.js +++ b/tests/create.js @@ -133,18 +133,27 @@ QUnit.module("mu-create/create#property"); - QUnit.test("prototype", function (assert) { + QUnit.test("prototype instance", function (assert) { assert.expect(1); + var p = {}; var C = create(proto)({ - "a": 1, - "b": 2 + "prototype": p }); - assert.propEqual(C.prototype, { + assert.strictEqual(C.prototype, p, "instance is equal"); + }); + + QUnit.test("prototype property", function (assert) { + assert.expect(1); + var p = { "a": 1, "b": 2 - }); + } + + var C = create(proto)(p); + + assert.propEqual(C.prototype, p, "properies are equal"); }); QUnit.test("regexp", function(assert) {