I’m trying to remove the value of an array, without removing its methods. Consider the following code:
var Project = function () {
//The array where all data will be stored before they are sent..
this.data = [];
// ... Along with a function to send data to other source ...
this.data.send = function () {
}
//Here is where the data would be altered ...
//Send the data ...
this.data.send();
//Remove the data, we don't want it when sending the next time ...
this.data = [];
// ... but this (obviously) results in the removal of the send() function ... :-(
}
Which also will remove the function .send(), which is not the behavior I’m looking for. What’s the smoothest and most proper way to dodge this problem? Thanks!
Sirko’s suggestion should work, but your issue points to design flaw, in my opinion.
Why not expose an array like object, with methods that never changes, but has an internal array it can manipulate at will.
Let arrays be arrays, and use other constructs to manipulate them.