prototype1.4简介_yj
下面的例子用提示框显示0-9。 <script>
function demoTimes(){ var n = 10;
n.times(function(index){ alert(index); });
/*************************** * you could have also used: * (10).times( .... ); ***************************/ }
</script>
<input type=button value="Test Number.times()" onclick="demoTimes()">
让我们看看如何运用这些扩展。
<input type=checkbox id=myChk value=1> Test? <script>
//declaring the class
var CheckboxWatcher = Class.create();
//defining the rest of the class implementation CheckboxWatcher.prototype = {
initialize: function(chkBox, message) { this.chkBox = $(chkBox); this.message = message;
//assigning our method to the event
this.chkBox.onclick =
this.showMessage.bindAsEventListener(this); },
showMessage: function(evt) {