-
-
Notifications
You must be signed in to change notification settings - Fork 11
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
instanceof
?
#4
Comments
wrapping the P.S. right now |
True enough - added that check in ljharb/object.assign@59b94e0 but I'll wait on the |
uhm ... it might be a long wait ... 'cause I want to see how this ends up: they have I just don't fancy too much the idea of wrapping the I should change the |
I'm fine leaving this open as long as necessary :-) The way |
can I have a use case for this request, beside the aim to the perfect shim that we know already is not possible? |
Wrapper for |
That's a spec error in Chrome - |
The primary use case is to eliminate as many caveats as possible, so the list is both exhaustive and small. If it ends up being impossible, so be it, but I still believe it is possible :-) |
sorry but I've asked for a use case ... I see most of the things I am putting in completely pointless for the real-world, and since it's clear this is a sham I wonder why should I pollute and wrap the global Object for something useless. In order to retrieve Symbols you need special methods, accoridngly what is the point to have that What is the use case for having it, beside spec compliance for a thing that is not compliant anyway? |
Any type-checking library, or polymorphic function, which needs to check its arguments may use this approach - many of my shims do. I'm not obsessively attached to |
I've tried already twice to wrap the global Object resulting in any sort of problems in every devce I could test ... so to me it's not sensible to wrap the global Object, it's a thing I haven't even thought about since those times where wrapping global Array was giving you access to defined properties in order to hack security here and there ... I don't know if I'd personally would ever trust a library that swaps natives ... that being said ... I don't think anyone would ever pass symbols around just for fun because these cannot be used as objects. I'd arguably say that
can you please think about a real-world use case that would make me think it's a good idea to wrap native Sorry for being difficult but I hate messing up natives, I feel already guilty enough here with all the hacks I've created already ... |
There's tons of use cases for passing around It's fine if you aren't willing to do it, or if it turns out not to be practical, but I still think it's important to bring it up, and attempt it. |
meaning you know these are Symbols .. you don't accept/use random signals you are not aware of, right?
again, you need to know which constant you are referencing In both cases you don't/won't need the If I search Accordingly, I'd like to see a real-world code where the check |
meaning, the code testing that it's the semaphore, and not something else, needs to be able to concretely determine that it's a I do not believe |
you cannot guard against sham ... if you want to deal with real |
however, if you want to create a "loosey" function isSymbol(o) {
return typeof o === "symbol" || (
typeof o === "object" &&
o in Object.prototype &&
o.constructor === Symbol &&
!(o instanceof Symbol)
);
} There is no possible other way to polyfill them in ES5 so that would be a good way without going too dirty ... then if somebody wants to play bad games in there, you already have a problem: you have bad libraries in your core, get rid of them ... right ? :D |
actually updated the check, so it's more duck-type centric ;-) |
Right, this is what I'm saying - I'm saying that if I want to start making my code not depend on native The |
btw, I'm going to sleep now ... I'll leave this bug open waiting to see what happens around ... if these are must have requirements for real-world needs I'll find a way to sqeeze changes in. Or maybe I'll wake up tomorrow and push all the changes ... who knows, right now I'm using Symbols for a side project and these works great. I understand also concerns of best possible poly ever to filer ... but again I'm not concerned about other polyfills for symbols and I always know what code runs in my projects. A dirty approach, a dirty library, that wants to hack Symbol shams, won't make a minute live in any production (and shouldn't, so not a real problem) |
so drop that line and trust that if a typeof variable is an object and its constructor is Symbol and its not an instanceof its own constructor then, by specs, that's a symbol (beside the typeof object, but there's nothing we can do here, it's already good it's not typeof string) Even thenables are that easy to assume ;-) |
I don't currently have |
OK, sorry I'm late here for an answer. But reading recent update on redefining Promise and the fact it's consider future hostile, I think I won't overwrite the global Apologies for any inconvenience. |
That comment thread applies to replacing the global |
I think is generally considered a future hostile practice to overwrite any global. I don't want to do that specially with Until I'll see the usage of |
Now that objects are returned from
Symbol()
, could we makeSymbol() instanceof Symbol
befalse
, butObject(Symbol()) instanceof Symbol
betrue
? It'd require wrappingObject
itself, and some prototype chain reorganization so that{} instanceof Object
remainedtrue
, but it should be doable. You maybe could even makeSymbol() instanceof Object
befalse
, but that's probably harder.The text was updated successfully, but these errors were encountered: