var user = functopn(usName){ this.name = usName; // метод установки имени this.setName =function(newName){ this.name = newName; } // 2-й метод, задает новое имя Tolbase this.newName = function(){ this.setName('Tolbase'); } } 

The 2nd method is wrong. So how to call a method inside another method?

  • Why erroneous? var u = new user ('lol'); alert (u.name); u.newName (); alert (u.name); Works out as it should. - Sh4dow
  • Yes! Do-but! I understood why it does not work for me, but I don’t know what to do with it if the method suggests the following construction: this.newNmae = function () {setInterval (function () {this.setName ('Tolbase');}, 1000); }, you know what I mean? - Smash
  • I understand and they answered you correctly) - Sh4dow

1 answer 1

Forgot new yet. otherwise, the user will remain a function and not become an object, as a result user.setName will be undefined .

 var user = new function(usName){ this.name = usName; var _user = this; // метод установки имени this.setName =function(newName){ _user.name = newName; } }