一区二区久久-一区二区三区www-一区二区三区久久-一区二区三区久久精品-麻豆国产一区二区在线观看-麻豆国产视频

Prototype 學(xué)習(xí) Prototype對(duì)象

環(huán)境:
Prototype Version: '1.6.1_rc3'
Aptana Studio, build: 1.2.5.023247
IE7
FF2.0.0.4
Opera 10 beta
復(fù)制代碼 代碼如下:
var Prototype = {
Version: '1.6.1_rc3',
//定義瀏覽器對(duì)象
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對(duì)象
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對(duì)象是通過調(diào)用匿名函數(shù)并且立即執(zhí)行的方式返回的,執(zhí)行匿名函數(shù)的方法有三種:
1. (function(){return 1})() //()可以強(qiáng)制求值,返回函數(shù)對(duì)象然后執(zhí)行函數(shù)
2. (function(){return 1}()) //返回函數(shù)執(zhí)行的結(jié)果
3. void function(){alert(1)}() //void 也有強(qiáng)制運(yùn)算的用法
其中判斷Opera的方法isOpera用到了window.opera,在Opera瀏覽器中會(huì)返回一個(gè)對(duì)象,其它瀏覽器返回undefined
BrowserFeatures對(duì)象主要判斷瀏覽器的一些特性,F(xiàn)F支持許多的特性在IE下不支持,比如document.evalute方法就可以通過XPATH的方式操作HTML文檔,但I(xiàn)E就不支持。
此函數(shù)詳細(xì)用法如下:
復(fù)制代碼 代碼如下:
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__這個(gè)在FF下可以取得對(duì)象的prototype對(duì)象,即對(duì)象的原型。這也是Javascript繼承機(jī)制的基礎(chǔ),基于原型的繼承,不像通常的C++,Java,C#語言的基于類的繼承。還有一種metaclass的繼承方式,在ruby和Python中常有應(yīng)用
其中ScriptFragment定義網(wǎng)頁中引用腳本的正則表達(dá)式
JSONFilter:還是引用prototype原文的解釋更清楚他的用法――
復(fù)制代碼 代碼如下:
/*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就是返回第一個(gè)參數(shù)的方法:
復(fù)制代碼 代碼如下:
Prototype.K('hello world!'); // -> 'hello world!'
Prototype.K(1.5); // -> 1.5
Prototype.K(Prototype.K); // -> Prototype.K

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

JavaScript技術(shù)Prototype 學(xué)習(xí) Prototype對(duì)象,轉(zhuǎn)載需保留來源!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請(qǐng)第一時(shí)間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 娇小videosbest8另类| 久久伊人精品热在75 | 久久亚洲aⅴ精品网站婷婷 久久亚洲不卡一区二区 | 亚洲国产成人综合精品2020 | 久久福利一区二区 | 久久99国产一区二区三区 | 日本欧美一区二区免费视 | 一级做a爰片性色毛片新版的 | 91中文在线 | 99视频福利 | 久久怡红院国产精品 | 91福利网站 | 91视频精选| 四虎影视成人永久在线观看 | 国内自拍第一页 | 我要看三级全黄 | 国产免费观看视频 | 亚洲一区第一页 | 麻豆xfplay国产在线观看 | 国产精品免费一区二区三区四区 | 午夜免费观看_视频在线观看 | 麻豆国产精品免费视频 | 在线亚洲成人 | 国产亚洲高清在线精品99 | 91精品国产99久久 | 国产成人精品日本亚洲直接 | 丁香婷婷在线 | 国产精品毛片一区二区三区 | 91正在 播放| 视色4se成人午夜精品 | 日韩在线视频中文字幕 | 精品72久久久久久久中文字幕 | 国产乱码精品一区二区三上 | 国产在热线精品视频国产一二 | 亚洲区小说区激情区图片区 | 美女精品一区二区 | 日本激情视频网站w | 五月月色开心婷婷久久合 | 91亚洲国产成人久久精品网址 | 国产福利精品在线 | 婷婷色婷婷|