3

I investigated that if I modify prototype of object String it takes more time to evaluate compare with global function.

Basic example:

String.prototype.test = function() { 
  return this.charCodeAt(0);
}
'test string'.test();

Is a much slower than:

function globalTest(str) {
  return str.charCodeAt(0);
}
globalTest('test string');

To more complex test see this jsperf statistic: http://jsperf.com/string-prototype-or-function

0 Answers0