Не передается значение в переменную
function Rectangle(w, h) {
this.width = w; } Rectangle.prototype.downShow = function() { this.width = this.width - 1; document.write(rect1.width) } var rect1 = new Rectangle(100, 200); setInterval(rect1.downShow, 200); Не передается значение свойства width объекта rect1 в функцию dawnShow, от этого не срабатывает setInterval, не могу понять почему. |
Изменения в коде
Прошу прощения не правильно скорректировал код
function Rectangle(w) { this.width = w; } Rectangle.prototype.downShow = function() { this.width = this.width - 1; document.write(rect1.width) } var rect1 = new Rectangle(100); setInterval(rect1.downShow, 200); |
Изменения в коде
Прошу прощения не правильно скорректировал код
function Rectangle(w) { this.width = w; } Rectangle.prototype.downShow = function() { this.width = this.width - 1; document.write(rect1.width) } var rect1 = new Rectangle(100); setInterval(rect1.downShow, 200); |
function Rectangle(w) { this.width = w; var that = this; this.downShow = function() { that.width = that.width - 1; console.log(that.width, rect1.width); } } var rect1 = new Rectangle(100); setInterval(rect1.downShow, 200); |
Цитата:
<!DOCTYPE html> <html> <head> <meta http-equiv='Content-Type' content='text/html; charset=windows-1251' /> <!-- <script src='http://code.jquery.com/jquery-latest.js'></script> <script src="https://code.angularjs.org/1.3.9/angular.min.js"></script> <script src="https://code.angularjs.org/1.3.9/angular-route.js"></script> --> <style type='text/css'> </style> <script type='text/javascript'> function Rectangle(w) { this.width = w; } Rectangle.prototype.downShow = function() { this.width = this.width - 1; document.write(rect1.width) } var rect1 = new Rectangle(100); setInterval(rect1.downShow, 200); </script> </head> <body> </body> </html> |
ksa,
Где же он работает, когда все время 100, а должно уменьшаться <!DOCTYPE html> <html> <head> <script type='text/javascript'> function Rectangle(w) { this.width = w; var that = this; this.downShow = function() { that.width = that.width - 1; document.write(rect1.width + " "); } } var rect1 = new Rectangle(100); setInterval(rect1.downShow, 200); </script> </head> <body> </body> </html> |
Цитата:
ТС писал, что Цитата:
|
Часовой пояс GMT +3, время: 22:02. |