What's the difference between using function with parameter THIS or OBJ?

3

Now, when I try to use a function, when I put this as a parameter, it was not executed, but when I put OBJ, it worked normally. Can anyone tell me the difference between the two?

function mostraCampo(obj) {
          var select = document.getElementById('instituição')
          if (select.value == 'OUTRA') {
            document.getElementById("outrainst").style.visibility = "visible";
          } else{
            document.getElementById("outrainst").style.visibility = "hidden";
          }
        }
<div class="form-group">                
          <label> Instituição de ensino <br />
            <select class="form-group" name="instituição" id="instituição" onchange="mostraCampo(this.value);">
              <option value="UFTM">UFTM</option>
              <option value="UNIUBE">UNIUBE</option>
              <option value="FACTHUS">FACTHUS</option>
              <option value="SENAI">FAZU</option>
              <option value="IMEPAC">IMEPAC</option>
              <option value="NENHUMA">NENHUMA</option>
              <option value="OUTRA">OUTRA</option>
            </select>
            <input type="text" class="form-control" name="outrainst" id="outrainst" style="visibility: hidden;">
          </label>
        </div>
    
asked by anonymous 06.09.2017 / 17:02

1 answer

1

Well, if I understood correctly your question is because this is reserved by the parser, so you can not use it as a function parameter because it can be used inside it to set information in the function. You can put whatever name you really want, except the ones that are reserved by the system. Obj is another convention.

This is an example:

function Pessoa(){
  this.idade = 0;

  setInterval(() => {
    this.idade++; // propriedade |this|refere ao objeto pessoa
  }, 1000);
}

Then this is related to when you want to call the function itself. Since the obj is when you need to enter a parameter in the function, by convention, it uses obj, but it could be a snapshot that would work. It just can not be a reserved word.

    
21.10.2018 / 11:17