Using Class Variables in Javascript -
i trying create class in javascript (or whatever equivalent is) stores count in class variable constructor can assign id created objects. following:
shift = function(hour) { this.id = shift.idcount; shift.idcount++; } however have no thought idcount should initialized or defined. there way of doing this?
yes,
shift.idcount = 0; after definition of shift function.
that allows access current value of counter whenever want (if want). if don't want straight access value of counter, , don't want else either, utilize private variable within shift @pointy proposes.
javascript
No comments:
Post a Comment