Skip to content

Commit

Permalink
feat(prototype): added support for setting protype (#3)
Browse files Browse the repository at this point in the history
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"
```
  • Loading branch information
mikaelkaron authored Sep 22, 2016
1 parent e5e30e0 commit 8856c6f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
7 changes: 6 additions & 1 deletion prototype.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
});
19 changes: 14 additions & 5 deletions tests/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 8856c6f

Please sign in to comment.