javascript - Removing a variable's value without losing its children methods -


i'm trying remove value of array, without removing methods. consider following code:

var project = function () {      //the array data stored before sent..     this.data = [];      // ... along function send data other source ...     this.data.send = function () {     }      //here data altered ...      //send data ...     this.data.send();      //remove data, don't want when sending next time ...     this.data = [];     // ... (obviously) results in removal of send() function ... :-( } 

which remove function .send(), not behavior i'm looking for. what's smoothest , proper way dodge problem? thanks!

sirko's suggestion should work, issue points design flaw, in opinion.

why not expose array object, methods never changes, has internal array can manipulate @ will.

var data = {   items: [],   push: function(item) {     this.items.push(item);   },   send: function() {     // send items     this.items = [];   } }  data.push('abc'); data.send(); console.log(data.items.length) // 0 

let arrays arrays, , use other constructs manipulate them.


Comments

Popular posts from this blog

jasper reports - Fixed header in Excel using JasperReports -

media player - Android: mediaplayer went away with unhandled events -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -