I. JavaScript was originally a procedural
JavaScript, which dates back to the 1.0 age, is actually a process. There are only two basic features. One is the HTML
Tag to take over the event, for example:
<Input type = "button" onclick = "alert ('hello')">
The second option is to support a simple object constructor (function ). In fact, the constructor in this era is better than the initialization function. It should
Write as follows:
Function MyObject (){
This. xxx = '...';
This. yyy = '...';
}
Obj = new MyObject ();
Therefore, early JavaScript was undoubtedly carrying the name "Object-based procedural scripting language. Besides
For the above two features, JavaScript has the nature of some general scripting languages, such:
-The entire. js file is loaded to the execution environment (for example, a WEB browser) at a time. After a syntax analysis, the file is executed row by row;
-During the preceding syntax analysis period, (named) Functions and variables declared with "var" are pre-processed in an identifier table for use by script code;
-From the execution of global code lines or function calls, the code that cannot be executed in the whole process is not found in the error (except for the syntax check in step 1 ).
It also has the nature of common procedural languages, such:
-Statements such as if/for/while/switch are available;
-Declare a function with function, and use "(...)" to declare its form parameter table, as well as to indicate function call and parameter passing;
-Similar to the basic syntax of C language, including the use of "{...}" to represent the code block, and the use "! = "And other operators;
-A basic concept similar to the object operation operator "." in Java, as well as attributes and methods.
Now you see a basic JavaScript language. Its Code only has functions and statement lines like C, and supports a very simple area.
Program to an object. Okay, this is almost all about JavaScript ...... Hmm ...... All basic syntax concepts. If you use one
If you get started with a little bit of programming language, you will think JavaScript is actually quite simple.
Yes, "Write a function and call it" is that simple. For example:
Function hi (){
Alert ('hello, world .');
}
Hi ();
2. The data type is slightly more complex.
JavaScript has six basic data types. One type is the value type, that is, undefined, string, number, and boolean.
Is the reference type, that is, function and object. To check the type of data X, you can simply use "typeof X" to return a string.
In other advanced languages, the value type differs from the reference type by using "pass value or reference during access. Simply put, in the following function
Medium:
Function foo (X ){
}
X indicates the value itself or a reference pointing to the value (you can think of it as a pointer), indicating the type of X. Different from other languages
Yes. JavaScript does not add a indicator to the call entry to demonstrate the method of explicitly passing values. For example:
Function foo (var X ){
// In general advanced languages, var indicates that the reference of variable X is always input.
}
Instead, the script engine determines how to pass the Value Based on the Data Type of X actually passed in. For example:
Function foo (X ){
...
}
Foo ('20140901'); // <-string '20160901' Value
Foo (aObj); // <-aObj is an object reference
The key to such processing is that the JavaScript type system is concise enough. The six basic types include three philosophical concepts: executable
And non-executable; object or non-object; has (value) or no (value ). Obviously, it is not easy to understand this philosophical idea, because it is more complex.
The self-contained logic is: The function is also an object, the value is also an object, and the non-value is also a value.
This is all about JavaScript systems. If you want to use it easily, remember the following:
-Three simple value types: string, number, and boolean are used for display on the webpage;
-Objects are used to store other objects, funtion, or the preceding simple value types, and are found using an attribute name using the '.' operation;
-Undefined is used to check whether the data is valid or invalid;
-Function is used for execution.
Of course, if you want to become a thinker or linguistic madman, think about the philosophical proposition above and I will not block you.
3. What I can use my nose to figure out is the amount of data.
Many people may not understand the Direct Volume declaration in JavaScript, but it is indeed very simple. Since most of our advanced languages are
Constant declaration is supported, and even the original assembly language supports immediate values. For example:
// In C
# Define ABYTE 256
// In delphi
Const
ABYTE = 256
; In asm
Mov ah, 256
Of course, JavaScript ...... Yes ...... They can support direct traffic without any clear background-they are actually a concept. For example:
// In javascript
Var
AByte = 256
When you understand it, remember: In all the above Code, the so-called direct or immediate value refers to the '123', not
Variable or constant identifier ABYTE/aByte. Further, You Need To Know That JavaScript supports eight types of Direct Volume declarations:
--------------------
Numeric: supports integer, floating point, 0x, and other hexadecimal prefixes, and ...... And so on;
Boolean value: true/false;
No value: undefined;
Function: function () {...}, also known as an anonymous function;
String: Use '...' or "..." to support multiple lines and escape characters;
Regular Expression: Use/.../to support regular expressions such as g, I, and m;
Array: use [...] to support nested arrays;
Object: {...} is used. nested object declaration is supported;
--------------------
You can use the preceding characters as an entity and use them at any position in the code -- I mean expression or statement line. Just use your nose
The inference is:
// Since it can be written:
Aaa = 'hello, '+ 'World ';
// You can write:
Bbb = [1, 2, 3] + [4, 5, 6];
// You can also write:
Ccc =/abc/+/cdf/
// Similarly:
//......
As shown above, you can place all the direct quantities in the middle of an expression or statement. Occasionally, you may need to use a pair
Parentheses enclose this directly; otherwise, there will be syntax ambiguity, for example, the following:
Ddd = (function () {}) + (function (){})
Well, it's just that simple. You just need to expect that you have a non-degraded nose.
Iv. Prototype inheritance
Prototype inheritance may be the simplest thing in the world.
Let's assume that an object is a table. The great Anders supports this assumption. He said that the JavaScript Object is a "Property package "--
Such a table stores "name/value" pairs such as "name = value. When we want to use the following code:
AObj. name
When you look for a value, check it in the table (people using delphi should remember TStringList ). Object.
In my previous understanding, it was "a struct with an inheritance relationship (struct/record )". So what is the inheritance relationship?
In this case, if the search fails, you only need to find the prototype of the aObj object for prototype inheritance.
This prototype is also an object, which is recorded in the prototype attribute of the constructor function. For example:
Function MyObject (){
//...
}
MyObject. prototype = xxx;
Var aObj = new MyObject ()
Zzz = aObj. name;
When the name attribute cannot be found in aObj, according to the above rules, it will go to the xxx object, that is, try to find "xxx. name ".
Xxx itself is also an object, and there will also be a constructor function (such as xxxObject (), so when xxx. name cannot be found, it will
Go to xxxObject. prototype to find ...... So ...... Such in-depth mining will never be found again ...... Returns undefined.
It's easy. Prototype inheritance is just a simple search rule.
On the other hand, you need to make aObj accessible to a member, and you just need to modify the prototype of it (or they -- are similar to aObj instances ).
That's all. This is very common in JavaScript. For example, you want all strings to have a certain attribute:
String. protoype. MyName = 'string'
For example, if you want all objects to have a certain attribute (or method, or something else), then:
Object. prototype. getMyName = function (){
Return this. MyName;
}
How nice it is. Now the String can also get myname, and the function can also get myname. All the names without names also have names -- of course, the name
The word is undefined.
This article from the CSDN blog, reproduced please indicate the source: http://blog.csdn.net/aimingoo/archive/2008/10/06/3022379.aspx