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
Object.getPrototypeOf #6
Comments
That looks interesting, I tried to get a shim for this before based on John Resig's blog post but couldn't get it to work cross browser, this version looks a little more robust however, thanks for pointing it out. |
I've taken a closer look at this version of the shim and I'm not sure it can ever reliably work in IE. Because it eventually fallsback to checking For example if the prototype is defined without an object literal the result is as expected:
However if the prototype is defined using an object literal the constructor prototype points to Object.prototype
I have set up a little test that demonstrates this here. If this is correct then I'm not sure it is a good idea to include the shim as part of augment, ideally all shims should behave very closely to the native implementations. Otherwise you will get different behaviour for the same methods depending on which browser they run in. I'm more than willing to be proved wrong however, if you can see a way to make this behave as expected I'd be very happy to include it as part of augment. |
This is a generally-known problem (regarding the difference-in-operation on I.E. versus, well, the rest of the world); how about instead exposing a cross-browser-consistent version of the I.E. functionality called |
Thats an interesting approach to the problem. I don't think there is anyway to implement Object.getPrototypeOf in JavaScript in a cross browser way. I'm not sure however that adding non-standard methods to augment is the correct way to solve this problem. I think your |
I’d agree, except that this is something that is “reliably implementable” everywhere except out-of-date IEs. In my opinion, out-of-date IEs “don’t matter,” beyond minimum efforts to make things work even to some minimal extent. Any sysadmin forcing an ancient IE upon their users is basically signing them up for the Shitty Web™, so there’s not a lot of point in wasting time/effort on it, or making a product of a lower quality overall just to pander to them. … all that said, you, as the maintainer of this project, may disagree. ;D |
Object.getPrototypeOf is a simple In IE browsers it's a simple The only case it breaks if people use The solution is warning people not to write bad code rather then not giving people a method that works. |
@ELLIOTTCABLE - the main reason to use augment.js is to be able to seamlessly use the more modern JavaScript methods in old browsers such as IE. TBH if you are not supporting IE less than 8 you probably aren't getting a huge amount of benefit from augment.js since the browser share of old versions of safari, firefox etc are quite small. @Raynos - if the Perhaps this method could be added, with the caveat that you must set the constructor property in your prototype in IE if you are defining a prototype using an object literal. I guess without augment.js you would have to do this anyway to get similar behaviour. Ideally I would like to be able to throw some kind of error in IE if I'll try and put something together this week, I'd appreciate any feedback on the implementation once its done. |
@olivernn that’s entirely my point. This only doesn’t work in the case of Not a big deal either way, I suppose. ^_^ |
Okay this is what I have so far, this does work in IE.
I'm toying with the idea of adding a check to the IE version that throws a warning if you are setting the prototype using an object literal but haven't set the
The problem with this would be if you were calling |
… that test is already incorrect, right off the bat, isn’t it? As |
Yeah good catch - was just hoping that there was a way to catch the case where the prototype was assigned to an object literal but constructor hadn't been set. TBH trying to catch it will probably cause more problems then it would solve. I'll try and put together a release sometime this week with |
I've just released version 0.4.0 of augment that includes the discussed implementation of |
See shim :
http://forrst.com/posts/Object_getPrototypeOf_shim-eNB
It might be worthwhile to add this to augment.
The text was updated successfully, but these errors were encountered: