-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
es6.spec.symbols transformer: add instanceof
transformation
#1364
Comments
I don't understand, can you elaborate on what currently happens and what you expect to happen?
|
Aren't symbols primitives and not objects? Firefox gives me: > Symbol() instanceof Symbol
false
// Behaves the same as for example strings
> String() instanceof String
false What I think @getify means is, to implement the Symbol |
|
Nope, this issue has nothing to do with "symbol instanceof Symbol". That's why I mentioned the Code that illustrates: function Foo(greeting) {
this.greeting = greeting;
}
// override `instanceof` behavior for instances of `Foo`
Foo[Symbol.hasInstance] = function(inst) {
return inst.greeting == "hello";
};
var a = new Foo( "hello" ),
b = new Foo( "world" );
a instanceof Foo; // true
b instanceof Foo; // false Edit: The original code above has an inaccuracy. Here's the corrected section: // override `instanceof` behavior for instances of `Foo`
Object.defineProperty(Foo,Symbol.hasInstance,{
value: function(inst) {
return inst.greeting == "hello";
}
});
|
I have not considered implementation details. Does seem like a problem at first glance. Perhaps Remember, I'm asking for this support in an optional transformer, so the (significant) costs of the spec compliancy around symbols only matter to those who care about spec compliancy with symbols. Alternately, perhaps this should be its own additional transformer? |
At a minimum, this needs to be documented what the support is, one way or the other. I spent over an hour combing through the docs to figure out if this was supported somewhere that I was just missing. |
@zloirock Could
The docs for es6.spec.symbols are pretty clear/concise. |
It took an hour to find that specific one, since I hadn't previously been familiar with the optional transformers in that level of detail. These sorts of limitations (or oversights, whatever) weren't mentioned at all in any of the FAQ's or polyfills or caveats pages, which is where I spent that time looking first. To clarify, what I mean is that the polyfills/caveats/faq's pages could be clearer about calling out the fact that there are things which the spec calls for which aren't by default transformed, and require you to go looking for the optional transformers for such things. |
Yeah, the spec transformers should be mentioned in the caveats. On Tue, Apr 28, 2015 at 2:28 PM, Kyle Simpson notifications@github.com
|
@sebmck I don't think replacing correct I will add |
It’s impossible to catch var foo = function () {};
var bar = “bind”;
foo[bar](); then unless you wrap all member expressions too. How far is too far? On Tue, Apr 28, 2015 at 3:05 PM, Denis Pushkarev notifications@github.com
|
@sebmck I mean add with instanceof helper, not for if(!Function.prototype.bind.__wrappedForHasInstance__)
var _bind = Function.prototype.bind;
Function.prototype.bind = function(){
var result = _bind.apply(this, arguments);
if(Symbol.hasInstance in this)Object.defineProperty(result, Symbol.hasInstance, {
enumerable: true,
writable: true,
configurable: true,
value: this[Symbol.hasInstance]
});
return result;
}
Function.prototype.bind.__wrappedForHasInstance__ = true;
} It's better then slowdown w/o this optional transformer. |
As in, add that to the top of every file? |
Together with instanceof helper. |
The |
Anyway, wrapper for correct |
Just a suggestion. |
[Instead of opening a new issue, I'm going to post this question here, so please reopen. Am also happy to spin off a new issue thread if more appropriate.] I appreciate the support added here for transforming Some of them are probably possible to do similar to the Here are the Well Known Symbols:
So, from this list, specifically the ones that are not already supported, is it feasible to support any of them?
Thoughts? |
@getify I don't wanna add |
@getify |
OK, I figured that would be the conclusion. Should I submit a PR to the babel site repo that adds such to the "caveats" page? |
Sure, would be appreciated! On Wed, Apr 29, 2015 at 2:43 PM, Kyle Simpson notifications@github.com
|
…[@@hasInstance] being nonwritable #1364
It seems that currently
@@hasInstance
symbol support isn't in place, which means thatinstanceof
checks aren't able to be overriden. I think in the same way thattypeof
checks are transformed with the optionales6.spec.symbols
, so shouldinstanceof
checks.The text was updated successfully, but these errors were encountered: