JS 고급---bind 방법의 사용

1748 단어

bind 방법의 사용


 
    // , , 
    function ShowRandom() {
      //1-10 
      this.number = parseInt(Math.random() * 10 + 1);
    }

    // 
    ShowRandom.prototype.show1 = function () {
      // this , winddow, 
      window.setInterval(this.show2.bind(this), 1000);
    };

    // 
    ShowRandom.prototype.show2 = function () {
      // 
      console.log(this.number);
    };
    // 
    var sr = new ShowRandom();
    //   
    // , 
    sr.show1();

좋은 웹페이지 즐겨찾기