Created
April 29, 2012 18:06
-
-
Save petermichaux/2552304 to your computer and use it in GitHub Desktop.
JavaScript's new and map don't play well together
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var todoViews = todoModels.map(function(todoModel) { | |
return new TodoView(todoModel); | |
}); | |
// if Function.prototype.new is defined or TodoView.new is defined using "this" | |
var todoViews = todoModels.map(TodoView.new, TodoView); | |
// if Todo.new is defined without using "this" | |
var todoViews = todoModels.map(TodoView.new); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@cjohansen on Firefox performance of Object.create vs new is not really different (it's slightly faster on benchmark that's it), on V8 it is noticeable in real world. Hopefully one day V8 will have it fixed. I also do not tend to worry about things prematurely ;)