-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make Freezer extendable (closes #22) #26
Conversation
1) We extend `Freezer.prototype` but not replace it. 2) We have restore non-enumerable members of `Freezer.prototype` we need. The of non-enumerable member of `Freezer.prototype` is `Freezer.prototype.constructor`.
Cool, this solution is simple and elegant! I will commit it later when I get out of work. |
@marquex @arqex , diff --git a/src/freezer.js b/src/freezer.js
index ed9a488..2c72cff 100644
--- a/src/freezer.js
+++ b/src/freezer.js
@@ -65,7 +65,7 @@ var Freezer = function( initialValue, mutable ) {
this._events = [];
}
-Freezer.prototype = Utils.createNonEnumerable({}, Emitter);
+Freezer.prototype.__proto__ = Emitter;
//#build
module.exports = Freezer; But this way is not standard-compliant (precise: is not ES5-compliant, but it is ES6-compliant because Another side you use |
See #27 for it |
Hi @kuraga Freezer should work in most browsers, and unfortunatelly It is true that it is used by freezer to extend arrays, but there is a fallback for the browsers that don't support it. That's why I think that using I would do something like: Freezer.prototype = Utils.createNonEnumerable({constructor: Freezer}, Emitter); |
It doesn't work if the constructor is not enumerable? |
Ah, now I understand what do you mean. I just want to use |
So I want something like // object_assign is like Object.assign: it merges arguments in one object
var newPrototype = object_assign(Freezer.prototype, {constructor: Freezer});
Freezer.prototype = Utils.createNonEnumerable(newPrototype, Emitter); |
Sure, So a freezer prototype would be: Freezer.prototype = Utils.createNonEnumerable({constructor: Freezer}, Emitter);
// Prototoype
Freezer.prototype; // { constructor: Freezer }
Freezer.prototype.prototype: // Emitter It should work with ES6, shouldn't it? |
I'm talking about one thing only: first argument of |
And in this line: Freezer.prototype = Utils.createNonEnumerable({constructor: Freezer}, Emitter); first argument ( |
@@ -65,7 +65,9 @@ var Freezer = function( initialValue, mutable ) { | |||
this._events = []; | |||
} | |||
|
|||
Freezer.prototype = Utils.createNonEnumerable({}, Emitter); | |||
Freezer.prototype = Utils.createNonEnumerable(Freezer.prototype, Emitter); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you see what I changed in THIS (68) line? That's I'm talking about.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Everything work without this change! But I think this change is right!!!
There is nothing bad with that. In fact, until that line is executed But we really don't care about what the prototype was because we are setting a new one, that is what |
It is empty for me but is it always guaranteed to be empty? |
Another side, its enumerable part is guaranteed empty... Ok, sorry for my fault brainstorm. One moment. |
Sure, it is guaranteed. Freezer is a function defined just in the previous instruction. |
Close in favour of #29 |
Freezer.prototype
but not replace it.Freezer.prototype
we need.The one is non-enumerable member of
Freezer.prototype
isFreezer.prototype.constructor
.