Javascript进阶
2010-09-14 13:44:42 来源:WEB开发网其在jQuery源代码中的使用:
// Mozilla, Opera and webkit nightlies currently support this event
if ( document.addEventListener ) {
// Use the handy event callback
document.addEventListener( "DOMContentLoaded", function(){
document.removeEventListener( "DOMContentLoaded", arguments.callee, false );
jQuery.ready();
}, false );
// If IE event model is used
} else if ( document.attachEvent ) {
// ensure firing before onload,
// maybe late but safe also for iframes
document.attachEvent("onreadystatechange", function(){
if ( document.readyState === "complete" ) {
document.detachEvent( "onreadystatechange", arguments.callee );
jQuery.ready();
}
});
通过前面的讲解,最后再看看下面这个例子:
var Class = {
create : function() {
return function() { this.initialize.apply(this, arguments); }
}
};
var vehicle = Class.create();
vehicle.prototype = {
initialize : function(type){
this.type=type;
},
showSelf : function(){
return 'this vehicle is ' + this.type;
}
};
var moto = new vehicle('Moto');
log.info(moto.showSelf());
现在,大家可以看明白这个例子吗?
五、References
http://www.javascriptkit.com/jsref/
http://www.quirksmode.org/js/this.html
http://www.blueidea.com/tech/web/2007/4855.asp
http://blog.csdn.net/mumuTiger/archive/2008/03/25/2217731.aspx
http://www.cn-cuckoo.com/wordpress/wp-content/uploads/2007/08/JavaScriptClosures.html
Tags:Javascript 进阶
编辑录入:爽爽 [复制链接] [打 印]更多精彩
赞助商链接