The difference between two ways of Object reset and emptying of js objects

the following code indicates that the pop-up box will be emptied when the pop-up box is closed, that is, clearFlag is false, in case there is cache information the next time the pop-up box is opened.
but when the pop-up box fills out the form, save and get the information. Once the method is cleared, the save will not get the data, which is the""value. Method 2 can get the value normally.
could you tell me the specific difference between the two methods:

   clearFalg(){  
            if(this.clearFalg == false){
                //: this.subForm.tempInventoryId ="" 
                //:
                          this.subForm = {
                             tempInventoryId:""
                           }
                
            }
        }
Jun.25,2021

you must have done the assignment

var data = this.subForm;

this.subForm.tempInventoryId =''

data.tempInventoryId //''

reference problem
the first data and this.subForm use the same references, so they influence each other
the second this.subForm points to a new reference again, so they don't affect

.
Menu