Add method to Array in Javascript
Posted
by
user1167650
on Stack Overflow
See other posts from Stack Overflow
or by user1167650
Published on 2012-07-10T21:09:23Z
Indexed on
2012/07/10
21:15 UTC
Read the original article
Hit count: 141
JavaScript
Is it possible to add a method to an array() in javascript? (I know about prototypes, but I don't want to add a method to every array, just one in particular).
The reason I want to do this is because I have the following code
function drawChart()
{
//...
return [list of important vars]
}
function updateChart(importantVars)
{
//...
}
var importantVars = drawChart();
updateChart(importantVars);
And I want to be able to do something like this instead:
var chart = drawChart();<br>
chart.redraw();
I was hoping there was a way I could just attach a method to what i'm returning in drawChart()
. Any way to do that?
© Stack Overflow or respective owner