JavaScript Advanced Programming Reading notes 2

Source: Internet
Author: User
Tags access properties array length function prototype try catch hasownproperty

<! DOCTYPE html>//The document type of this Web page, this is the HTML5 notation
Some HTML elements and CSS properties used by bootstrap require a document type of HTML5 doctype. So this document type must appear at the beginning of each page of the project


There are two versions of jQuery available for download:
Production version-used in the actual website, has been streamlined and compressed.
Development version-for testing and development (uncompressed, readable code)
These two versions are available for download from jquery.com.
Tip: You can put the download file in the same directory as the page, which makes it easier to use.
If you don't want to download and store JQuery, you can also refer to it through a CDN (content distribution network).

Both Google and Microsoft have jQuery in their servers.

To refer to JQuery from Google or Microsoft, use one of the following codes:
Google CDN:

<script src= "Http://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js" >
</script>
Tip: Get the latest available version from Google CDN:

If you look at what Google URL is-Specify the JQuery version (1.8.0) in the URL. If you want to use the latest version of JQuery, you can also delete a number from the end of the version string (example 1.8), Google will return to the latest available version of the 1.8 series (1.8.0, 1.8.1, etc.), or the first number can be left, then Google will return 1 The latest available version in the series (from 1.1.0 to 1.9.9).
Microsoft CDN:

<script src= "Http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.0.js" >
</script>

Tip: Using Google or Microsoft's jQuery, there's a big advantage:

Many users have already loaded jQuery from Google or Microsoft while visiting other sites. All the results are that when they visit your site, JQuery is loaded from the cache, which reduces the load time. At the same time, most cdns ensure that when a user requests a file, the response is returned from the server closest to the user, which can also increase the load speed.

Basic types and reference types:
1 adding properties only to reference types dynamically
2 var object2 = Object1 (var object1 = new Object ()), just create a new pointer to the original heap in memory of the object, when the object changes, two pointers to the value of the reference will change (reference delivery). Base type with replication (value passing) data exists in the stack
3 The difference between passing parameters: Before overriding the parameters of a reference type within a function, even if the value of the parameter is changed, the reference is still valid and the override is a local object, which is destroyed immediately after the function is executed.

The operator typeof () is useful when checking the base type (a string that returns a type), but instanceof is required to check the reference type (otherwise only object is returned)
Variable execution environment and scope chain, two ways to extend the scope chain: with and the catch in the try catch, the property automatically inherits the variables in parentheses
JavaScript does not have block-level scopes, variables declared in functions that are not VAR by default are global variables, and the execution environment is the global environment
Query identifier level up query, if an identifier is found in the current function environment discard up query
Memory recovery mechanism

Object objects are instances of reference types:
Two ways to create an object instance: New and object literal (looks more concise, also pro-gaze when a large number of arguments are passed)
Two ways to Access object properties: Accessing attributes (square brackets) and points (more respected) through variables

Array
1 There are two ways to create an instance of an array
2 The property of the array length is not read-only, can be modified, the deletion of redundant data, change the General Assembly appears undefined data
3 detection is data, generally instanceof is enough, but if the Web page to use more than one frame, there may be an array redefinition, need to use Array.isarray () to detect
4 Conversion Method: ToString (Call the ToString method on each element), tolocalestring (Call the toLocaleString method for each element), valueOf
The 5 Join () method is used to put all the elements in an array into a string. The elements are delimited by the specified delimiter.
6 provides a stack-like operation method operation Array (return value array length, below): Pop and push, stack top array end
7 provides a way to manipulate arrays of queues: Push and shift (take out the elements of the head) pop and unshift can simulate the queue in the opposite direction
8 reordering methods: Reverse and Sort,sort Default in ascending order, call each element's ToString method and then sort by character order, this is obviously not our purpose, you can use a comparison function as its argument, the return value is the sorted array
9 How to: Concat creates a new array based on all items in the current array, slice creates a new array based on one or more items in the current array (use many, see the book)
IndexOf, LastIndexOf from behind, not found return-1, the second parameter indicates a lookup start
11 Iterative methods: Every, filter, ForEach, some, map
12 Shrinking method: Don't know what the hell

Date
Date.parse () and DATE.UTC (), the former converts a string to a date, and also the ToString method, Tolocalestring,valueof returns the number of milliseconds to facilitate comparison

function
Function names are variables, so functions can be used as values (you can pass a function as a parameter or return a function)
Properties inside the function: arguments, an array of parameter objects whose properties are callee a pointer to the function that owns the array
Properties of the Function object: the number of the length parameter, prototype, which cannot be enumerated
Methods of functions apply and call, using the method of one object to another object
Bind ()

Boolean and numeric type and string type
Overriding the ToString method, toLocaleString, ValueOf, the boolean of the base type and the reference type are very different, preferably not with a Boolean of reference type
Number also overrides three methods, the first returns the value of the string, the third returns the value of the base type, and the first one can also set the parameter control to convert the string into the binary
ToFixed () returns a string form in the specified decimal place format
Toexponential () returns a string in the form of an exponent, which can also specify a decimal place
Toprocession () returns the most appropriate format, or you can specify decimal digits
string-type character method: CharAt () charCodeAt ()
Slice (), substring (), substr (), the case of negative parameters
Trim () Returns a copy of the string and removes the front and back spaces
toLocaleUpperCase (), toUpperCase (), toLocaleLowerCase (), toLowerCase ()
The pattern-matching function of the string matches (), similar to the regular exec (), where the parameter is a regular object or regular expression
Another way to find the mode search (), the only argument is the same as match, returning the first time to find a matching character index
To simplify the operation of replacing substrings, the method replace () came into being
Split ();
Localecompare ();
fromCharCode ();

Built-in objects: programmers do not have to instantiate objects explicitly because they have been instantiated before the program is made.
Global: All methods and properties within the global domain that are not part of other objects are properties and methods of the global object
encodeURIComponent () and encodeURI () encode the generic resource identifier, which encodes only spaces, while the former encodes any non-standard characters. So it is common to use encodeurine for the entire URI and use encodeURIComponent for the string following the URI, which is used more in the actual use, because it is often necessary to query the string arguments instead of the URI itself
Contrary to the above methods decodeURI and decodeURIComponent, the former can only be encoded by the corresponding function of the part of transcoding
Eval () is able to interpret the code string and insert the interpreted code into the original execution space, although it is powerful, but in strict mode there is a problem, the part of user input is cautious, there is the problem of malicious user code injection
In addition to playing the global object in JavaScript, window plays a number of other roles

Math
Common Properties for objects: MATH.E, Math.PI ...
Min () and Max () methods
Apply ()
Rounding Method: Ceil (), floor (), round ()
Random ()

When accessing a base type in read mode, it is common for an object of the corresponding basic wrapper type to facilitate data manipulation, but once the statement of the operation's basic type is executed, the newly created wrapper object is immediately destroyed.

Data properties and Accessor properties
Configurabale,enumerable,writable,value
Configurabale,enumerable,get,set a common way to use accessor properties, which is to set the value of one property to cause other properties to change, browser compatibility issues, legacy non-standard implementations
Difinepropertities () defining multiple properties at once

Creating objects can take the factory pattern, abstract the creation code into functions, avoid code redundancy, and the problem is that the type of the object cannot be known
In the constructor mode, the first letter of the constructor is capitalized (for reference to other OO languages), and the new operator is used so that different instances have a constructor attribute as the constructor name, but the object type is still instanceof compared with the Of course, the constructor pattern is not without drawbacks, so the prototype pattern is created: All instances share a set of properties and methods that define properties and methods as properties and methods of the constructor prototype. By default, all prototype objects have a property constructor point to the constructor that owns the prototype, and within all instances there is a prototype property that points to the function prototype, not the constructor, although it is inaccessible to prototype in all implementations. However, you can use the function isprototypeof () to determine if the prototype is not an instance of the prototype, getprototypeof (), get the prototype object, take the instance property first find the instance has no this attribute value, cannot find the property value in the prototype, The instance's own property values can be shielded from the prototype's attribute values, and the function hasOwnProperty () can be used to detect whether the attribute is an instance or a prototype.
In operator, which returns true if the object can be accessed
Hasprototypepropertity (), returns False if the property value is overridden in the instance, because the instance no longer uses the property value in the prototype
For in returns all the enumerable properties that can be accessed through an object, including instance properties, which in itself stipulate that the properties set by the developer are enumerable (IE8 and previous exceptions)
The earlier iebug used for in to mask all default non-enumerable properties, including hasOwnProperty (), toString (), and so on, Ecma5script also set prototype and constructor as non-enumerable properties. But in different browsers to implement different
The method that gets all the enumerable instance property names of the Instance object keys (), which returns an array of strings
Gets the method getownpropertynames for all instance property names, whether enumerable or not
Use the object literal to write the prototype property to reduce the amount of code, but the property constructor point to object, if the constructor property is important, you can explicitly set the variable back, but then its access properties will be changed to enumerable (the default is not enumerable), There are new ways to see the book.
Overriding a prototype object disconnects an existing prototype from an instance that was previously created, and the pointer to the previous instance still points to the prototype object before the prototype rewrite
Native objects also have prototypes, or they can be modified by overriding the prototype method
However, the prototype method also has drawbacks: it is obvious that all instances of the prototype share the property is the biggest problem, the modification of one instance of its prototype property will cause another instance of the property changes, which is not what we normally need
So the most common approach is to use a custom pattern: constructors are used to define attributes of some personalities, while prototypes define common properties and methods
Dynamic prototype mode: When defining a prototype attribute, it is necessary to determine whether a property exists, if it does not exist, to create it, and the benefit is to reduce the number of times the code executes, creating a prototype property on the first call to the constructor, and then without executing the intermediate code
When none of the above modes are used, consider the parasitic construct, similar to Factory mode, but require new when creating an instance, which is used in special cases to create constructors for objects
Safe function mode: Do not apply new and this, avoid other applications to call the data, restrict access to the data, only through the method to obtain the property value, the last two method instances and the constructor does not have a relationship, the instanceof operator does not make sense




JavaScript Advanced Programming Reading notes 2

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.