KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I realize that, strictly speaking, this is not subclassing the array type, but will this work in the way one might expect, or am I still going to run into some issues with .length and the like? Are there any drawbacks that I would not have if normal subclassing were an option? function Vector() { var vector = []; vector.sum = function() { sum = 0.0; for(i = 0; i < this.length; i++) { sum += this[i]; } return sum; } return vector; } v = Vector(); v.push(1); v.push(2); console.log(v.sum());
Tags (comma-separated)
Save Edits
Cancel