WEB开发网
开发学院网页设计JavaScript Javascript进阶 阅读

Javascript进阶

 2010-09-14 13:44:42 来源:WEB开发网   
核心提示: 其在jQuery源代码中的使用://Mozilla,Operaandwebkitnightliescurrentlysupportthiseventif(document.addEventListener){//Usethehandyeventcallbackdocument.addEve

其在jQuery源代码中的使用:

Javascript进阶
 // 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();
   }
  });
Javascript进阶

通过前面的讲解,最后再看看下面这个例子:

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

上一页  2 3 4 5 6 7 

Tags:Javascript 进阶

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接