2
this.anim= true;

このオブジェクトの変数を秒false後に変更するにはどうすればよいですか?x

4

1 に答える 1

6
this.anim = true;
var that = this; // you store the reference to a `this` in `that` variable,
                 // so you could use it in a callback function. You have
                 // to do that because it has its own `this` defined
setTimeout(function() {
    that.anim = false;
}, x * 1000);

また

this.anim = true;

(function(that){ // you create an IIFE (see http://tinyurl.com/js-iife)
    setTimeout(function() {
        that.anim = false;
    }, x * 1000);
}(this)); // and invoke it with `this` as a parameter, which will be available
          // as `that` in the function body
于 2012-12-16T08:00:07.483 に答える