javascript - getting function itself among its parameters -


have simple function applying given attributes dom-element:

object.prototype.setattr = function(attr) { // attr object   ( var in attr )      this.setattribute( i, atr[i] ); };

in addition passed parameters i'm getting function setattr itself. can explain behavior?

you need use hasownproperty avoid looping through prototype chain.

since attr object , have added setattr prototype of object, attr has access setattr method through prototype chain.

object.prototype.setattr = function(attr) { // attr object    (var in attr) {      if (attr.hasownproperty(i))        this.setattribute(i, attr[i]);    }  };      item.setattr({    b: 1  });
<pre id="result"></pre>   <p id="item">item</p>


Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -