php – What is the difference between using a function with THIS or OBJ parameter?


Making a JavaScript code recently, I came across that when using a function, when I put THIS as a parameter, it wasn't 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>
            <input type="text" class="form-control" name="outrainst" id="outrainst" style="visibility: hidden;">


Well, if I understand your question correctly, it's because this is reserved by the parser, so you can't 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, minus the ones that are reserved by the system. Obj is more of a convention.

This serves as an example:

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

So this is related to when you want to call the function itself. Obj, on the other hand, is when you need to inform a parameter in the function, by convention, it uses obj, but it could be xuxa that it would work. It just cannot be a reserved word.

Scroll to Top