Skip to content

bind is fasterΒ #15

@trusktr

Description

@trusktr

newless/newless.js

Lines 50 to 61 in 3fe059f

// otherwise, create a dynamic function in order to use `new`
// Note using `function.bind` would be simpler, but is much slower:
// http://jsperf.com/new-operator-with-dynamic-function-vs-bind
"var argList = '';" +
"for (var i = 0, len = args.length; i < len; i++) {" +
"if (i > 0) argList += ',';" +
"argList += 'args[' + i + ']';" +
"}" +
"var constructCall = Function('constructor, args'," +
"'return new constructor(' + argList + ');'" +
");" +
"var value = constructCall(constructor, args);"

Right there, I visited that link, and it seems nowadays bind is a lot faster (in Chrome):

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions