You could use defineProperty
, which by default makes a property non-enumerable.
Object.defineProperty(
Array.prototype,
'addOrRemove',
{
get: function() {
return function(value) {
var index = _.indexOf(this, value);
if (index === -1) {
this.push(value);
} else {
this.splice(index, 1);
}
return this;
};
}
}
);
console.log([]);