天天躁日日躁狠狠躁AV麻豆-天天躁人人躁人人躁狂躁-天天澡夜夜澡人人澡-天天影视香色欲综合网-国产成人女人在线视频观看-国产成人女人视频在线观看

Prototype 學習 Prototype對象

環境:
Prototype Version: '1.6.1_rc3'
Aptana Studio, build: 1.2.5.023247
IE7
FF2.0.0.4
Opera 10 beta
復制代碼 代碼如下:
var Prototype = {
Version: '1.6.1_rc3',
//定義瀏覽器對象
Browser: (function(){
var ua = navigator.userAgent;
var isOpera = Object.prototype.toString.call(window.opera) == '[object Opera]';
return {
IE: !!window.attachEvent && !isOpera,
Opera: isOpera,
WebKit: ua.indexOf('AppleWebKit/') > -1,
Gecko: ua.indexOf('Gecko') > -1 && ua.indexOf('KHTML') === -1,
MobileSafari: /Apple.*Mobile.*Safari/.test(ua)
}
})(),
//定義瀏覽器Feature對象
BrowserFeatures: {
XPath: !!document.evaluate,
SelectorsAPI: !!document.querySelector,
ElementExtensions: (function() {
var constructor = window.Element || window.HTMLElement;
return !!(constructor && constructor.prototype);
})(),
SpecificElementExtensions: (function() {
if (typeof window.HTMLDivElement !== 'undefined')
return true;
var div = document.createElement('div');
var form = document.createElement('form');
var isSupported = false;
if (div['__proto__'] && (div['__proto__'] !== form['__proto__'])) {
isSupported = true;
}
div = form = null;
return isSupported;
})()
},
ScriptFragment: '<script[^>]*>([//S//s]*?)<//script>',
JSONFilter: /^///*-secure-([/s/S]*)/*///s*$/,
emptyFunction: function() { },
K: function(x) { return x }
};
if (Prototype.Browser.MobileSafari)
Prototype.BrowserFeatures.SpecificElementExtensions = false;

Broswer對象是通過調用匿名函數并且立即執行的方式返回的,執行匿名函數的方法有三種:
1. (function(){return 1})() //()可以強制求值,返回函數對象然后執行函數
2. (function(){return 1}()) //返回函數執行的結果
3. void function(){alert(1)}() //void 也有強制運算的用法
其中判斷Opera的方法isOpera用到了window.opera,在Opera瀏覽器中會返回一個對象,其它瀏覽器返回undefined
BrowserFeatures對象主要判斷瀏覽器的一些特性,FF支持許多的特性在IE下不支持,比如document.evalute方法就可以通過XPATH的方式操作HTML文檔,但IE就不支持。
此函數詳細用法如下:
復制代碼 代碼如下:
var xpathResult = document.evaluate(xpathExpression, contextNode, namespaceResolver, resultType, result);

The evaluate function takes a total of five arguments:
xpathExpression: A string containing an xpath expression to be evaluated
contextNode: A node in the document against which the Xpath expression should be evaluated
namespaceResolver: A function that takes a string containing a namespace prefix from the xpathExpression and returns a string containing the URI to which that prefix corresponds. This enables conversion between the prefixes used in the XPath expressions and the (possibly different) prefixes used in the document
resultType: A numeric constant indicating the type of result that is returned. These constants are avaliable in the global XPathResult object and are defined in the relevaant section of the XPath Spec. For most purposes it's OK to pass in XPathResult.ANY_TYPE which will cause the results of the Xpath expression to be returned as the most natural type
result:An existing XPathResult to use for the results. Passing null causes a new XPathResult to be created.
其中__proto__這個在FF下可以取得對象的prototype對象,即對象的原型。這也是Javascript繼承機制的基礎,基于原型的繼承,不像通常的C++,Java,C#語言的基于類的繼承。還有一種metaclass的繼承方式,在ruby和Python中常有應用
其中ScriptFragment定義網頁中引用腳本的正則表達式
JSONFilter:還是引用prototype原文的解釋更清楚他的用法――
復制代碼 代碼如下:
/*String#evalJSON internally calls String#unfilterJSON and automatically removes optional security comment delimiters (defined in Prototype.JSONFilter).*/

person = '/*-secure-/n{"name": "Violet", "occupation": "character"}/n*/'.evalJSON() person.name; //-> "Violet"

/*You should always set security comment delimiters (/*-secure-/n...*/) around sensitive JSON or JavaScript data to prevent Hijacking. (See this PDF document for more details.)*/

Prototype.K就是返回第一個參數的方法:
復制代碼 代碼如下:
Prototype.K('hello world!'); // -> 'hello world!'
Prototype.K(1.5); // -> 1.5
Prototype.K(Prototype.K); // -> Prototype.K

說明一下JavaScript里面的靜態方法和實例方法
靜態方法要這樣擴展:
Date.toArray=function(){}
那么toArray方法就是Date的靜態方法,不能這樣調用(new Date()).toArray();否則會拋出異常
要這樣用:Date.toArray()
實例方法要這樣擴展:
Date.prototype.toArray2=function(){}
那么toArray2方法就是Date的實例方法了,不能這樣調用Date.toArray2();
要這樣用:(new Date()).toArray2()

JavaScript技術Prototype 學習 Prototype對象,轉載需保留來源!

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

主站蜘蛛池模板: 亚洲欧美在无码片一区二区 | 青柠在线观看免费高清电视剧荣耀 | 天天躁人人躁人人躁狂躁 | 四房色播手机版 | 无码内射成人免费喷射 | 亚洲一区二区三区乱码在线欧洲 | 久久99精国产一区二区三区四区 | 色悠久久综合 | 國產麻豆AVMDXMDX| 免费国产久久啪久久爱 | 美女扒开屁股让男人桶 | 99久久精品国产自免费 | 亚洲色偷偷偷网站色偷一区人人藻 | 在线中文字幕网站 | 999久久久无码国产精蜜柚 | 九九热在线视频 | 极品虎白在线观看 | 玩弄朋友娇妻呻吟交换电影 | 办公室沙发口爆12P 办公室日本肉丝OL在线 | 台湾佬综合娱乐网 | 少妇第一次交换 | 午夜人妻理论片天堂影院 | 一本二卡三卡四卡乱码麻豆 | 511麻豆视传媒精品AV | 迅雷成人论坛 | 菠萝蜜国际一区麻豆 | 中文字幕人成乱码中国 | 日本在线高清不卡免费播放 | 久久精品手机观看 | 果冻传媒在线观看高清完整免费 | 做i爱视频30分钟免费 | 国产亚洲精品久久久久久久 | 久久这里只精品热在线99 | 国产精品一区二区制服丝袜 | 亚洲在线视频自拍精品 | 免费国产综合视频在线看 | gogo免费在线观看 | 国产国拍精品AV在线观看 | 日日射日日操 | 冈本视频黄页正版 | 久久人妻少妇嫩草AV无码 |