paul_cheung

导航

Types in Javascript(jQuery)

Types in Javascript(jQuery) - beastid - pauls bloggerString: 空字符串等于Boolean的false;

Types in Javascript(jQuery) - beastid - pauls bloggerhtmlString: 包括起始tag和结束tag的字符串,代表html代码;

Types in Javascript(jQuery) - beastid - pauls bloggerNumber:双精度64位,跟string一样属于immutable,基于c语言的运算符都适用于此值;0默认为false,!0为true;

                Math函数,parseInt函数(各进制到int的转换);

                转换为字符串,""+1+2==“12”,""+(1+3)==“4”......

                NaN,非Number的对象会返回NaN,用isNaN函数判断;Number类型;

                Infinity,1/0==infinity;Number类型;

                Note:NaN==NaN is false,Infinity==Infinity is true;

                Integer属于Number类型,必须为非浮点数;

                Float属于Number类型,为浮点数;

Types in Javascript(jQuery) - beastid - pauls bloggerBoolean: true or false;

Types in Javascript(jQuery) - beastid - pauls bloggerObject:  var x = {}; {}的类型为object,默认值false;

                   var y = {name: "Pete",age: 15};

                   Types in Javascript(jQuery) - beastid - pauls blogger使用dot访问对象的属性:y.name or y.age;

                    Types in Javascript(jQuery) - beastid - pauls blogger使用array索引访问,y[name],y[age]

                    Types in Javascript(jQuery) - beastid - pauls blogger迭代for(key in y){ //do sth with key, and access value using y[key]};

                         Note:使用其他library的时候,可能扩展了Object.prototype,so take care!如:jQuery.each(obj,function(key,value))){}

                 Note:javascript对象没有继承机制,a workaround是使用prototype满足继承关系:   

                         var Employee = function(name, title) {                                                                      this.name = name;                                                                      this.title = title;                                                                      this.greet = function() {                                                                                         if (this.canTalk) {                                                                                                                        console.log("Hi, I'm "+this.name+", the "+this.title);                                                                                                                   }                                                                                                           }                                                                                           }                         var Customer = function(name) {this.name = name;}                         var Mime = function(name) {this.name = name;this.canTalk = false;}                         var Person = {

                                               canTalk : true,

                                               greet : function() {                                                                                    if (this.canTalk) {console.log("Hi, I'm "+this.name)}

                                                                           }                                                 }

                       继承机制为prototype;                        Customer.prototype = Person;                        Employee.prototype = Person;                       Mime.prototype = Person;                       var bob = new Employee('Bob','Builder');              var joe = new Customer('Joe');              var rg = new Employee('Red Green','Handyman');              var mike = new Customer('Mike');              var mime = new Mime('Mime');              bob.greet();              joe.greet();              rg.greet();              mike.greet();              mime.greet(); Types in Javascript(jQuery) - beastid - pauls bloggerArray: var x=[]; var y=[1,2,3];数组的类型为object,使用索引读写数组;无论空否,数组默认为true;

          Types in Javascript(jQuery) - beastid - pauls blogger数组迭代使用y=a.length作为终止条件,只读一次属性,速度比使用a.length作为终止条件快;

          Types in Javascript(jQuery) - beastid - pauls bloggerfor ( var i = 0, item; item = a[i]; i++ ) {// Do something with item}此时数组不能为空;

          Types in Javascript(jQuery) - beastid - pauls bloggervar x=[1,2,3]; jQuery.each(x,function(index,value){//do sth with index and value});

          Types in Javascript(jQuery) - beastid - pauls bloggervar x=[]; x.push(1); x[x.length]=2;  x is [1,2];

          Types in Javascript(jQuery) - beastid - pauls bloggersupport method: reverse, join, shift, etc.

          Types in Javascript(jQuery) - beastid - pauls bloggerArray<Type>在Jquery中表示方法需要的参数类型是数组,且元素类型是指定值;

Types in Javascript(jQuery) - beastid - pauls bloggerPlainObject: jQuery.isPlainObject(object)判断对象是否由{}或new Object(){}创建;

Types in Javascript(jQuery) - beastid - pauls bloggerFunction:  命名函数和匿名函数;

                 Types in Javascript(jQuery) - beastid - pauls bloggerArguments

                    function log( x ) {console.log( typeof x, arguments.length );}                     log(); // "undefined", 0                     log( 1 ); // "number", 1                     log( "1", "2", "3" ); // "string", 3

                    Note:上面的log函数体中,arguments变量总是有效的,arguments变量有length,callee(调用者)等属性;

                    var awesome = function(){return arguments.callee;}

                    awesome()==awesome   //true;

                  Types in Javascript(jQuery) - beastid - pauls bloggerContext,Call,Apply

                     "this"引用当前context,默认引用window对象,在function中可以改变context;

                      Function.prototype.call() and Function.prototype.apply(); refer to here and here.

                     NOTE: call和apply的异同:1.无参数时两者无区别;2.函数带参数时候,call(this,argumentsList),而apply (this,argumentArray);

                  Types in Javascript(jQuery) - beastid - pauls bloggerScope: 变量的作用域;

                  Types in Javascript(jQuery) - beastid - pauls bloggerClosures:

                        function create() {                                                          var counter = 0;                                                          return {

                                                                        increment: function() {counter++;},

                                                                        print:function() {console.log( counter );}

                                                                     }                                                      }                         var c = create();                         c.increment();                         c.print();                         The pattern allows you to create objects with methods that operate on data that isn't visible to the outside—the very basis of object-oriented programming.

                   Types in Javascript(jQuery) - beastid - pauls bloggerProxy Pattern

Types in Javascript(jQuery) - beastid - pauls bloggerCallback: 

                  Types in Javascript(jQuery) - beastid - pauls bloggerCallback is a plain JavaScript function, or sometimes just an event;

                  $( "body" ).click(function( event ) {                            console.log( "clicked: " + event.target );

                                                                      });                   Types in Javascript(jQuery) - beastid - pauls bloggerSome callbacks are required to return something, others make that return value optional. To prevent a form submission, a submit event handler can return false:

 
$( "#myform" ).submit(function() { return false; }); Types in Javascript(jQuery) - beastid - pauls bloggerselector:
        Types in Javascript(jQuery) - beastid - pauls bloggersome plugin will leverage jQuery's selector.

 

                   for instance, validation plugin accepts a selector to specify a dependency, whether an input is required or not:

                   emailrules:{required:"#email:filled"}

Types in Javascript(jQuery) - beastid - pauls bloggerEvents: blur,focus, load, resize, scroll, unload, beforeunload, click, dblclick, mousedown, mouseup, mousemove, mouseover, mouseout, mouseenter, mouseleave, change, select, submit, keydown, keypress,and keyup.

 

Types in Javascript(jQuery) - beastid - pauls bloggerjQuery: jquery object is a collection of DOM elements, it behaves much like an array but not actually a Javascript Array;

                  you will use the jQuery() function to create a jQuery object. jQuery() can also be accessed by its familiar single-character alias of $(), unless you have called jQuery.noConflict() to disable this option. Many jQuery methods return the jQuery object itself, so that method calls can be chained:

 
       $( "p" ).css( "color", "red" ).find( ".special" ).css( "color", "green" );     
Types in Javascript(jQuery) - beastid - pauls blogger
会对jQuery对象进行筛选,如find(),这些操作会返回一个经过筛选的新的jQuery对象;需要返回前一个jQuery对象则用.end().
      出的jQuery对象为empty,则最后的操作对DOM没有影响。
Types in Javascript(jQuery) - beastid - pauls blogger
XMLHttpRequest: 有些AJAX返回XHR object,或者作为参数传递给success/error/complete hanlders,可以在其他操作中使用这个对象。
                   NOTE:Ajax只有在request使用此对象的情况下才返回该对象。

Types in Javascript(jQuery) - beastid - pauls bloggerjqXHR: 从jquery1.5开始,$.ajax()返回jqXHR对象,which is a superset of the XMLHTTPRequest object.

Types in Javascript(jQuery) - beastid - pauls bloggerDeferred Object(延迟对象): 使用自我管理的callback queues注册多个callback,按需调用。

Types in Javascript(jQuery) - beastid - pauls bloggerPromise Object:此对象提供延迟对象的方法子集(then,done,fail,always,pipe,isResolved,isRejected),防止用户更改延迟对象。

Types in Javascript(jQuery) - beastid - pauls bloggerCallbacks Object:使用方法$.Callbacks()来create或者返回Callbacks对象,此对象用途广泛,比较强大的功能是用来管理callback lists。

Types in Javascript(jQuery) - beastid - pauls bloggerXML Object:一个由浏览器的XML DOM parser创建的文档对象,一般来自一个代表XML的字符串,XML文档与HTML语法不同,但jQuery的大多数遍历或操作都适用于此对象(XML文档)。

                                     

 

仅作个人学习只用,转载注明原文出处,引自:http://api.jquery.com/Types/

posted on 2013-07-15 17:14  paul_cheung  阅读(241)  评论(0编辑  收藏  举报