Environment:
Prototype Version: ' 1.6.1_RC3 '
Aptana Studio, build:1.2.5.023247
IE7
FF2.0.0.4
Opera Ten Beta
Copy Code code as follows:
var Prototype = {
Version: ' 1.6.1_rc3 ',
Defining Browser objects
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)
}
})(),
Define browser feature objects
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;
The Broswer object is returned by calling an anonymous function and executing it immediately, with three different methods of executing an anonymous function:
1. (function () {return 1}) ()//() Can force evaluation, return function object and execute function
2. (function () {return 1} ())//Returns the result of function execution
3. void function () {alert (1)} ()//void also has the use of forced operations
The way to judge Opera Isopera used Window.opera, in Opera browser will return an object, other browsers return undefined
Browserfeatures object mainly to determine some of the characteristics of the browser, FF support a number of features in IE does not support, such as the Document.evalute method can be XPath way to manipulate HTML documents, but IE does not support.
This function is detailed in the following directions:
Copy Code code as follows:
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 is evaluated
CONTEXTNODE:A node in the document against which the Xpath expression should is evaluated
Namespaceresolver:a function that takes a string containing a namespace prefix from the XPathExpression and returns a str ing 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 t He document
Resulttype:a numeric constant indicating the type of result this is returned. These are constants are avaliable in the global Xpathresult object and are defined in the the XPath Spec. For most purposes it's OK to pass in Xpathresult.any_type which would cause the results of the Xpath expression to be Retu Rned as the most natural type
Result:an existing Xpathresult to use for the results. Passing null causes a new Xpathresult to is created.
The __proto__ is the prototype object, which is the prototype of the object, which can get the object under FF. This is also the basis of the JavaScript inheritance mechanism, based on prototype inheritance, unlike the usual c++,java,c# language of class-based inheritance. There is also a metaclass way of inheriting, which is often applied in Ruby and Python.
Where scriptfragment defines a regular expression that references a script in a Web page
Jsonfilter: Or quoting the prototype of the original to make his usage more clear--
Copy Code code as follows:
/*string#evaljson internally calls String#unfilterjson and automatically removes optional security comment delimiters (de Fined 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 Preven T hijacking. (Here is a PDF document for more details.) */
PROTOTYPE.K is the way to return the first argument:
Copy Code code as follows:
PROTOTYPE.K (' Hello world! '); -> ' Hello world! '
PROTOTYPE.K (1.5); -> 1.5
PROTOTYPE.K (PROTOTYPE.K); -> PROTOTYPE.K
Explain the static methods and instance methods inside JavaScript
Static methods are extended like this:
Date.toarray=function () {}
So the ToArray method is the static method of date, which cannot be called (New Date ()). ToArray (); otherwise it throws an exception
To use this: Date.toarray ()
The instance method expands like this:
Date.prototype.toarray2=function () {}
So the ToArray2 method is the instance method of date, and cannot call Date.toarray2 ();
To do this: (New Date ()). ToArray2 ()