Skip to content Skip to sidebar Skip to footer

Array.prototype.sort.apply( Somearray, Args ) Vs Somearray.sort.apply( Somearray, Args )

Is there a substantial difference between the following two implementations of a sorted_copy function (NOTE: only their last lines differ): /* version 1 */ function sorted_copy (

Solution 1:

Array.prototype.sort. and someArray.sort. (note the trailing dots) is exactly the same thing, so there's no difference. Array.prototype.sort() and someArray.sort() are different, but that's another question.

For performance reasons, it might be better to use Array.prototype, since you can cache it in your namespace, see e.g. underscore sources.

Post a Comment for "Array.prototype.sort.apply( Somearray, Args ) Vs Somearray.sort.apply( Somearray, Args )"