看板java
标 题Re: [情报] Java 即将加入 Closure
发信站台大电机 Maxwell BBS (Wed Aug 30 21:11:10 2006)
转信站ptt!ctu-reader!Spring!news.nctu!news.ntu!bbs.ee.ntu!Maxwell
※ 引述《[email protected] (qazxsw99)》之铭言:
: 而我想问一下,以下是Closure的基本应用吗?
: 像javascript可以把function当作参数传送
: : ex:
: function sayhello() {
: alert('hello');
: }
: var f = sayhello
: f(); //此时同等於呼叫sayhello function
: 这只是最基本的应用,我个人认为啦...
function Robot() {
var createTime = new Date();
this.getAge = function() {
var now = new Date();
var age = now - createTime;
return age;
}
}
var robbie = new Robot();
window.onload = function() {
alert(robbie.getAge());
}
摘自Ajax in action 附录 B。。。
--
\,`/ / 。。。 嗨!
_).. `_
( __ -\
'`.
( \>_-_,
_||_ ~-/ http://caterpillar.onlyfun.net/
--
※ Origin: 台大电机 Maxwell 站 ◆ From: 218-166-217-253.dynamic.hinet.net