-8

I am learning to make library like jquery and trying to understand a piece of code where this.e is giving me hard time, where this 'e' come from and they are assigning object to it but when they return this they return just this not this.e .

function _(a) {
  var b = {
    key: "some val"
  };
  if (a) {
    if (window === this) {
      return new _(a)
    }
    this.e = document.getElementById(a);
    return this
  } else {
    return b
  }
}
_.prototype = {
    hide: function() {
      this.e.style.display = "none";
      return this
    }

HTML

<button onclick="_('abc')">click</button>
<div id="abc" style="width: 200px; height: 100px; background-color: pink;">   </div>
karthikr
  • 97,368
  • 26
  • 197
  • 188
user6920839
  • 57
  • 1
  • 5
  • 4
    `this.e` comes from `this.e = document.getElementById(a);`. If that doesn't answer your question I think you need to give a bit more details about what part is confusing you, EG. why are you confused about `this.e = X` but not confused about `_.prototype = Y`? – Paul Nov 01 '16 at 23:45
  • see: http://stackoverflow.com/questions/13418669/javascript-do-i-need-to-put-this-var-for-every-variable-in-an-object – Ahmad Sanie Nov 01 '16 at 23:45
  • because prototype is a there, that is builtin thing – user6920839 Nov 01 '16 at 23:46
  • You should research dynamic programming language. You can assign anything to an object at run time. – KnowHoper Nov 01 '16 at 23:47
  • `.e` is an object property named `e`. `this.foo = 'bar';` --- that's how you set the `'bar'` string to the `foo` property of the `this` object. – zerkms Nov 01 '16 at 23:47
  • okeyyy so "this" is an object a built in object and we are adding a property to that object okey gr8 understood – user6920839 Nov 01 '16 at 23:49
  • @user6920839 Just a heads up, the accepted answer *is wrong*. – Andrew Li Nov 02 '16 at 04:37

1 Answers1

-3

It's just a convention to use e as function parameter name when the parameter is event. as in your example here the event is onclick

peter
  • 1
  • 5