Can Javascript Prototype Pattern Performance Be Improved -


i have read creation of objects via prototypes faster , uses less memory closures because closures need re-create functions. accessing function on object's prototype little slower because needs traverse prototype chain further find function.

i wondering if adding reference in constructor prototype function increase performance minimal memory , initial setup impact. can achieved this...

function customer2(name) {     this.name = name;     this.greet = this.constructor.prototype.greet; } customer2.prototype = {     constructor: customer2,     greet: function () {         return this.name + ' says hi!';     } }; 

here add variable this.greet references prototype function save on traversal time.

could effective method @ increasing performance , keeping memory consumption low? cause side effects such problems inheritance?

jsperf link: http://jsperf.com/prototype-pattern-local-reference

so far jsperf seems support idea (except firefox seems favor closures setup doesn't make sense, maybe i've done wrong). of course, small example few test samples, , doesn't show memory consumption, thought might help.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -