Prototype learning Prototype object_prototype
Environment:
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',
// Define browser object
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 the browser Feature object
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: '',
JSONFilter: /^/*-secure-([sS]*)*/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. There are three ways to execute an anonymous function:
1. (function(){return 1})() //() can force evaluation, Return the function object and then execute the function
2. (function(){return 1}()) //Return the result of function execution
3. void function(){alert(1)}() //void is also available Usage of forced operation
Among them, the method of determining Opera is isOpera uses window.opera, which will return an object in the Opera browser, and other browsers return undefined
The BrowserFeatures object mainly determines some features of the browser, and FF supports many Features are not supported under IE. For example, the document.evalute method can operate HTML documents through XPATH, but IE does not support it.
The detailed usage of this function is 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 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.
Among them, __proto__ can obtain the prototype object of the object under FF, that is, the prototype of the object. This is also the basis of the JavaScript inheritance mechanism, prototype-based inheritance, unlike the usual class-based inheritance in C, JAVA, and C# languages. There is also a metaclass inheritance method, which is often used in ruby and python.
The ScriptFragment defines the regular expression that references the script in the web page
JSONFilter: It is better to quote the original explanation of the prototype to make its usage clearer -
/*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 is to return the first One-parameter method:
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 in JavaScript
The static method should be extended like this:
Date.toArray=function(){}
Then the toArray method is Date Static methods cannot be called like this (new Date()).toArray(); otherwise an exception will be thrown.
To be used like this: Date.toArray()
The instance method should be extended like this:
Date.prototype. toArray2=function(){}
Then the toArray2 method is the instance method of Date. Date.toArray2() cannot be called like this;
It should be used like this: (new Date()).toArray2()

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



JSON (JavaScriptObjectNotation) is a lightweight data exchange format that has become a common format for data exchange between web applications. PHP's json_encode() function can convert an array or object into a JSON string. This article will introduce how to use PHP's json_encode() function, including syntax, parameters, return values, and specific examples. Syntax The syntax of the json_encode() function is as follows: st

Here's how to convert a MySQL query result array into an object: Create an empty object array. Loop through the resulting array and create a new object for each row. Use a foreach loop to assign the key-value pairs of each row to the corresponding properties of the new object. Adds a new object to the object array. Close the database connection.

Use Python's __contains__() function to define the containment operation of an object. Python is a concise and powerful programming language that provides many powerful features to handle various types of data. One of them is to implement the containment operation of objects by defining the __contains__() function. This article will introduce how to use the __contains__() function to define the containment operation of an object, and give some sample code. The __contains__() function is Pytho

Wedge We know that objects are created in two main ways, one is through Python/CAPI, and the other is by calling a type object. For instance objects of built-in types, both methods are supported. For example, lists can be created through [] or list(). The former is Python/CAPI and the latter is a calling type object. But for instance objects of custom classes, we can only create them by calling type objects. If an object can be called, then the object is callable, otherwise it is not callable. Determining whether an object is callable depends on whether a method is defined in its corresponding type object. like

In PHP, an array is an ordered sequence, and elements are accessed by index; an object is an entity with properties and methods, created through the new keyword. Array access is via index, object access is via properties/methods. Array values are passed and object references are passed.

Title: Using Python's __le__() function to define a less than or equal comparison of two objects In Python, we can define comparison operations between objects by using special methods. One of them is the __le__() function, which is used to define less than or equal comparisons. The __le__() function is a magic method in Python and is a special function used to implement the "less than or equal" operation. When we compare two objects using the less than or equal operator (<=), Python

How to loop through Javascript objects? The following article will introduce five JS object traversal methods in detail, and briefly compare these five methods. I hope it will be helpful to you!

The Request object in PHP is an object used to handle HTTP requests sent by the client to the server. Through the Request object, we can obtain the client's request information, such as request method, request header information, request parameters, etc., so as to process and respond to the request. In PHP, you can use global variables such as $_REQUEST, $_GET, $_POST, etc. to obtain requested information, but these variables are not objects, but arrays. In order to process request information more flexibly and conveniently, you can
