I am working on a project where the new method is in the Array prototype:
Array .prototype.addOrRemove = function (value) {var index = _.indexOf (this, value); If (index === -1) {this.push (value); } And {it splice (index, 1); } Return it; }; This either adds a new value (if it is not present in the array) or removes it (otherwise). The strange thing is that when I type:
console.log ([]); I get the following output (in Chrome JS console):
[addOrRemove: function] I It was thought that only values in this type of console log should be present. Did I do something wrong or is it a normal behavior (looks strange anyway)? I appreciate some explanation.
You can use, which by default makes an asset non-computable
object.definproperty (array.prototype, 'addoremove'), {focus (function) (return function (value) {var index = _ index (this, value); if (index == = -1) {this.push (value);} and (this splice (index, 1);} return this;}}}}); console.log ([]);
No comments:
Post a Comment