-
-
Notifications
You must be signed in to change notification settings - Fork 18
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
add support for property descriptors #38
Conversation
@@ -37,7 +45,7 @@ function giveMethodSuper(superclass, name, fn) { | |||
|
|||
var sourceAvailable = (function() { | |||
return this; | |||
}).toString().indexOf('return this;') > -1; | |||
}).toString().indexOf('return this') > -1; |
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.
Some minification/obfuscation will remove the semicolon above this line and all hell breaks loose.
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.
can you submit this separately, this is pretty obvious good thing to get in asap. I would like to review the rest in more detail
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.
@stefanpenner for sure, done in #39
Ah, actually this didn't resolve the case of passing in getters and setters at instantiation time. Will add a test w/ code when I get some downtime. |
I'm unsure if we actually want to do this. Or can you provide a detailed example. I can totally see us wanting to support accessors at extend time though. |
|
||
if (typeof value === 'function' && hasSuper(value)) { | ||
target[key] = giveMethodSuper(getPrototypeOf(target), key, value); | ||
} else { | ||
target[key] = value; | ||
targetDescriptor = Object.getOwnPropertyDescriptor(target.__proto__, key); |
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.
i would love for us to use (or use a polyfil of) Object.getOwnPropertyDescriptors
(notice the plural form)
I am in favor of not supporting getters and setters at instantiation time. I think in any OO language, this would either be either discouraged or not/poorly supported. I figure a similar argument could be made against that behavior that was probably made in some form for not allowing the definition of computed properties on |
5654414
to
f3582c4
Compare
- support descriptors in assignProperties - add the getOwnPropertyDescriptors polyfill
f3582c4
to
ab513b7
Compare
@stefanpenner Added Also coalesced the property definition to one call to |
sounds good.
yup (it as perf related)
looks good. |
@bryanaka mind running the benchmarks again with the recent changes? I'm off vacation so my responses should be more timely now |
@stefanpenner sorry got this just as I was going on a vacation - now I am back :) Be aware that the numbers are going to look quite different since I am on a different machine than the previous benchmarks I ran. Before:
After:
Unfortunately |
ping @stefanpenner I know you are busy, just want to make sure if you'd like any further work done on this PR, I can start on it. |
this seems like a vary reasonable addition! Will investigate (and try not to forget) |
This does not appear to support Now that node 0.12 is dropped. One can actually use ES6 classes and CoreObject. I believe that may help? the following i believe works: class Foo extends CoreObject {
get name() { return 'hi'; }
} |
As we now have legit class syntax + super (node 0.12 is no longer supported), and that syntax supports accessors by default. I suspect we can close this. Will gladly reopen if I am mistaken. |
@stefanpenner I'm all for that. Less code == win in my book almost always One thing though is that if we want to recommend that usage when needing descriptors, the Would love to unite that concept but would be a huge breaking change just to get |
closes #29
Node Benchmarks: (couldn't get browser ones to work)
Before:
After:
extend is quite a bit slower, so might need to look at some optimizations somewhere (though create is the main piece we want performant).