Then of course JavaScript...must...can support it directly with a clear conscience - they are actually a concept. For example:
// in javascript
var
aByte = 256
But when understanding it, you must remember: in all the above codes, the so-called direct quantity or immediate value refers to the '256', not the
ABYTE/aByte, the identifier of a variable or constant. To go further, you need to know that JavaScript supports 8 types of direct quantity declarations:
--------------------
Values: Supports integers, floating point and 0x equal prefixes, and... etc.;
Boolean value: true/false;
No value: undefined;
Function: function() { ... }, also known as anonymous function;
String: Use '..' or ".." to support multiple lines and escape characters;
Regular expressions: use /../.., and support regular configurations such as g, i, m;
Array: Use [..], support nested arrays;
Object: Use {...}, supporting nested object declarations;
--------------------
You can use the above character quantity as an individual, anywhere in the code - I mean an expression or a statement line. Just use your nose
The inferences made are:
//Since you can write:
aaa = 'hello, ' + 'world';
//Then you can definitely write:
bbb = [1,2,3] + [4,5,6];
//It is also necessary to write:
ccc = /abc/ + /cdf/
//same:
// ……
As above, you can put all the direct quantities in the middle of an expression or statement. Occasionally, because of the necessity of syntax parsing, you may need to use a pair
Enclose this direct quantity in brackets - otherwise there will be ambiguity in syntax, such as the following:
ddd = (function() {}) + (function() {})
Okay, it’s that simple to measure directly, you just need to expect that you have a nose that has not degenerated.
4. 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 my assumption, saying that JavaScript objects are "properties packages" -
Such a table stores a "name/value" pair like "name=value". When we want to use the following code:
When you go to find the value, check it in the table (people who use delphi should remember TStringList). Object, oh, the so-called object—in
In my past understanding, it is "struct/record with inheritance relationship". So, what is the inheritance relationship?
That's it. If the search above is not successful, for prototype inheritance, you only need to search in the "prototype" of the object aObj and it will be done.
This prototype is also an object, recorded in the prototype property of the constructor function. For example:
function MyObject() {
// ...
}
= xxx;
var aObj = new MyObject()
zzz = ;
When the name attribute cannot be found in aObj, according to the above rules, you will search in the xxx object, that is, try to find "".
Since xxx itself is an object, there will also be a constructor function (such as xxxObject()), so when it cannot be found, it will
Go inside and find... so... so deep dig until you can't find it again... and return to undefined.
How simple it is. The so-called prototype inheritance is just a simple search rule.
Conversely, you need to make aObj accessible to a member, and you only need to modify the prototype of it (or them - a reference to an instance similar to aObj)
That's fine. This is very common in JavaScript. For example, you want all strings to have a certain property:
= 'string'
For example, if you want all objects to have a certain property (or method, or something), then:
= function() {
return ;
}
How beautiful, now String can getMyName, function can getMyName, and all those without names also have names - of course, names
The word is undefined.
If you don’t have a name, it’s also a name. I haven’t thought about whether you will become a philosophical madman. I’m sorry.
Previous page1234Next pageRead the full text