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

Set up subclassing using Object.create #3804

Closed
wants to merge 1 commit into from

Conversation

kuychaco
Copy link
Contributor

This change eliminates having to define and invoke a Surrogate function, makes the source code more readable, and reduces the size of the backbone.js framework.

Object.create sets up the prototype delegation relationship without calling the "parent" constructor function. This is more straight forward than using a Surrogate constructor function just for the sake of setting up subclassing.

This change eliminates having to define and invoke a Surrogate function, makes the source code more readable, and reduces the size of the backbone.js framework. 

Object.create sets up the prototype delegation relationship without calling the "parent" constructor function. This is more straight forward than using a Surrogate constructor function just for the sake of setting up subclassing.
@jridgewell
Copy link
Collaborator

#3553 😉. Thanks, though!

@kuychaco
Copy link
Contributor Author

@jridgewell, some thoughts - while similar to #3553, this isn't so much a "duplicate" as it is an alternative approach. With #3553 there were concerns with breaking backwards compatibility. Object.create is vanilla JS (part of the standard JS library since JavaScript 1.8.5), making backwards compatibility a non-issue. Thoughts?

@jridgewell
Copy link
Collaborator

Using native Object.create won't work for IE8 or below, which is even more of a breaking change. _.create will fall back to the Surrogate method when needed.

@akre54
Copy link
Collaborator

akre54 commented Sep 24, 2015

@kuychaco the "backwards compatibility" concerns from #3553 are about people using older versions of Underscore (which didn't have _.create), it's a separate concern from browser support. For what it's worth, Underscore relies on Object.create if it exists.

@kuychaco
Copy link
Contributor Author

Gotcha, thanks for clarifying!

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

Successfully merging this pull request may close these issues.

3 participants