Jak wiadomo, pola można modyfikować dowolny sposób (zmieniać typ, setować itd). Cóż, tak samo mi się wydawało w JS)
Mam taki sobie obiekt:
var Validator = function(salaryZl,salaryGr,dayHour,nightHour,isEmploy){
this.salaryZl = salaryZl;
this.salaryGr = salaryGr;
this.dayHour = dayHour;
this.nightHour = nightHour;
this.isEmploy = isEmploy;
this.state = false;
this.salary;
}
I pewnym miejscu wywołuje taką metodę:
this.dayHour = parseInt(this.dayHour,10);
console.log ("Its String? " + typeof (this.dayHour)); // String
Jak widać próbuje zmienić typ danych (Z string to int, a właściwie number). Myślałem, że mogę dowolny sposób modyfikować te pola, jednakże się myliłem, gdyż kolejne wywołanie odpowiada, że jest to String. Dlaczego?