javascript bind 的用法(2)

###html

```

<div id="box"></div>

```

###css

```

#box{
width: 100px;
height: 100px;
background-color: #0f9;
}

```

###js

```

var test = {
a: function() {
alert(this.id)
},
b: function() {

}
};

var box = document.getElementById('box');

box.onclick=function() {
test.a.bind(this)();
}

```

 

posted @ 2016-02-16 11:45  bronana  阅读(83)  评论(0编辑  收藏  举报