Skip to content
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

Standards compliant approach to allowing _.extend to copy ES5 Getters/Setters #986

Closed
wants to merge 2 commits into from

Conversation

kevinlacotaco
Copy link

Looked through the approaches in the past and saw they were not standards compliant.

Uses Object.defineProperty() and Object.getOwnPropertyDescriptor() which are at least partially supported back to IE8.

@michaelficarra
Copy link
Collaborator

Partial support on IE8 is deceptive. It supports them for DOM nodes only, which is basically useless.

@kevinlacotaco
Copy link
Author

Is there a list of supported browsers anywhere I should be looking at?

I could always put a check in to see if those methods are supported and then use that otherwise use the old approach.

@michaelficarra
Copy link
Collaborator

This would also introduce an inconsistency in the behaviour of _.extend in different browsers, which is exactly the opposite of underscore's goal of implementing a functional library that can be used in a browser-agnostic way.

@kevinlacotaco
Copy link
Author

The checks would add an inconsistency?

What browsers are supported?

It delegates to built-in functions, if present, so modern browsers will use the native implementations of forEach, map, reduce, filter, every, some and indexOf.

I don't really see how this is any different then delegating to the built in functions that underscore is already using.

I have pushed a version with checks.

@michaelficarra
Copy link
Collaborator

I think I know where the disconnect is. You probably think getters/setters either exist or don't. In some JS implementations, getters/setters exist, but there's no support for defining/describing them. So when encountering an object with getters/setters in one of these interpreters, you will have observable differences from the behaviour of the same object in an engine that supports defining/describing these properties. Does that make sense?

@jashkenas jashkenas closed this Jul 6, 2013
@dalgard
Copy link

dalgard commented Nov 25, 2013

This is still relevant, though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants