日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > javascript >内容正文

javascript

JavaScript- The Good Parts CHAPTER 2

發布時間:2025/7/14 javascript 20 豆豆
生活随笔 收集整理的這篇文章主要介紹了 JavaScript- The Good Parts CHAPTER 2 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

I know it well:
I read it in the grammar long ago.
—William Shakespeare, The Tragedy(悲劇;災難;慘案) of Titus Andronicus

This chapter introduces the grammar of the good parts of JavaScript, presenting a?quick overview of how the language is structured. We will represent the grammar?with railroad diagrams.

The rules for interpreting these diagrams are simple:

? You start on the left edge and follow the tracks to the right edge.
? As you go, you will encounter literals in ovals, and rules or descriptions in?rectangles.
? Any sequence that can be made by following the tracks is legal.
? Any sequence that cannot be made by following the tracks is not legal.
? Railroad diagrams with one bar at each end allow whitespace to be inserted?between any pair of tokens. Railroad diagrams with two bars at each end do not.

The grammar of the good parts presented in this chapter is significantly simpler than?the grammar of the whole language.

Whitespace

Whitespace can take the form of formatting characters or comments. Whitespace is?usually insignificant, but it is occasionally necessary to use whitespace to separate?sequences of characters that would otherwise be combined into a single token. For?example, in:

var that = this;

the space between var and that cannot be removed, but the other spaces can be?removed.

上圖如何看:

?下面圈紅的都是表示可以走的路

也就這幾種類型的可以走,其他都是不允許的

JavaScript offers two forms of comments, block comments formed with /* */ and?line-ending comments starting with //. Comments should be used liberally to?improve the readability of your programs. Take care that the comments always accurately describe the code. Obsolete(廢棄的;老式的) comments are worse than no comments.

The /* */ form of block comments came from a language called PL/I. PL/I chose?those strange pairs as the symbols for comments because they were unlikely to occur?in that language’s programs, except perhaps in string literals. In JavaScript, those?pairs can also occur in regular expression literals, so block comments are not safe for?commenting out blocks of code. For example:

/*var rm_a = /a*/.match(s); */

causes a syntax error. So, it is recommended that /* */ comments be avoided and //?comments be used instead. In this book, // will be used exclusively.

Names

A name is a letter optionally followed by one or more letters, digits, or underbars. A?name cannot be one of these reserved words:

abstract boolean break byte case catch char class const continue debugger default delete do double else enum export extends false final finally float for function goto if implements import in instanceof int interface long native new null package private protected public return short static super switch synchronized this throw throws transient true try typeof var volatile void while with

Most of the reserved words in this list are not used in the language. The list does not?include some words that should have been reserved but were not, such as undefined,NaN, and Infinity. It is not permitted to name a variable or parameter with a reserved?word. Worse, it is not permitted to use a reserved word as the name of an object?property in an object literal or following a dot in a refinement.

Names are used for statements, variables, parameters, property names, operators,and labels.

Numbers

JavaScript has a single number type. Internally, it is represented as 64-bit floating?point, the same as Java’s double. Unlike most other programming languages, there is?no separate integer type, so 1 and 1.0 are the same value. This is a significant convenience because problems of overflow in short integers are completely avoided, and?all you need to know about a number is that it is a number. A large class of numeric?type errors is avoided.

If a number literal has an exponent part, then the value of the literal is computed by?multiplying the part before the e by 10 raised to the power of the part after the e.So?100 and 1e2 are the same number.

Negative numbers can be formed by using the – prefix operator.

The value NaN is a number value that is the result of an operation that cannot produce a normal result. NaN is not equal to any value, including itself. You can detect?NaN with the isNaN(number) function.

The value Infinity represents all values greater than 1.79769313486231570e+308.

Numbers have methods (see Chapter 8). JavaScript has a Math object that contains a?set of methods that act on numbers. For example, the Math.floor(number) method?can be used to convert a number into an integer.

Strings

A string literal can be wrapped in single quotes or double quotes. It can contain zero?or more characters. The \ (backslash) is the escape character. JavaScript was built at?a time when Unicode was a 16-bit character set, so all characters in JavaScript are 16?bits wide.

JavaScript does not have a character type. To represent a character, make a string?with just one character in it.

?

The escape sequences allow for inserting characters into strings that are not normally permitted, such as backslashes, quotes, and control characters. The \u convention allows for specifying character code points numerically.

"A" === "\u0041"

Strings have a length property. For example, "seven".length is 5.

Strings are immutable. Once it is made, a string can never be changed. But it is easy?to make a new string by concatenating other strings together with the + operator.

Two strings containing exactly the same characters in the same order are considered?to be the same string. So:

'c' + 'a' + 't' === 'cat'

is true.
Strings have methods (see Chapter 8):

'cat'.toUpperCase( ) === 'CAT'

Statements

?

?

A compilation(編輯) unit contains a set of executable statements. In web browsers, each?<script> tag delivers a compilation unit that is compiled and immediately executed.Lacking a linker, JavaScript throws them all together in a common global?namespace. There is more on global variables in Appendix A.

When used inside of a function, the var statement defines the function’s private?variables.

The switch, while, for, and do statements are allowed to have an optional label prefix that interacts with the break statement.

Statements tend to be executed in order from top to bottom. The sequence of execution can be altered by the conditional statements (if and switch), by the looping?statements (while, for, and do), by the disruptive statements (break, return, and?throw), and by function invocation.

A block is a set of statements wrapped in curly braces. Unlike many other languages,blocks in JavaScript do not create a new scope, so variables should be defined at the?top of the function, not in blocks.

The if statement changes the flow of the program based on the value of the expression. The then block is executed if the expression is truthy; otherwise, the optional?else branch is taken.

Here are the falsy values:
? false
? null

? undefined
? The empty string ''
? The number 0
? The number NaN

All other values are truthy, including true, the string 'false', and all objects.

The switch statement performs a multiway branch. It compares the expression for?equality with all of the specified cases. The expression can produce a number or a?string. When an exact match is found, the statements of the matching case clause are?executed. If there is no match, the optional default statements are executed.

A case clause contains one or more case expressions. The case expressions need not be?constants. The statement following a clause should be a disruptive statement to prevent
fall through into the next case. The break statement can be used to exit from a switch.

The while statement performs a simple loop. If the expression is falsy, then the loop?will break. While the expression is truthy, the block will be executed.

The for statement is a more complicated looping statement. It comes in two forms.

The conventional form is controlled by three optional clauses: the initialization, the?condition, and the increment. First, the initialization is done, which typically initializes the loop variable. Then, the condition is evaluated. Typically, this tests the loop?variable against a completion criterion. If the condition is omitted, then a condition of?true is assumed. If the condition is falsy, the loop breaks. Otherwise, the block is executed, then the increment executes, and then the loop repeats with the condition.

The other form (called for in) enumerates the property names (or keys) of an object.On each iteration, another property name string from the object is assigned to the?variable.

It is usually necessary to test object.hasOwnProperty(variable) to determine whether?the property name is truly a member of the object or was found instead on the prototype chain.

for (myvar in obj) {if (obj.hasOwnProperty(myvar)) {...} }

The do statement is like the while statement except that the expression is tested after?the block is executed instead of before. That means that the block will always be executed at least once.

The try statement executes a block and catches any exceptions that were thrown by?the block. The catch clause defines a new variable that will receive the exception?object.

The throw statement raises an exception. If the throw statement is in a try block, then?control goes to the catch clause. Otherwise, the function invocation is abandoned,and control goes to the catch clause of the try in the calling function.

The expression is usually an object literal containing a name property and a message?property. The catcher of the exception can use that information to determine what to?do.

The return statement causes the early return from a function. It can also specify the?value to be returned. If a return expression is not specified, then the return value will?be undefined.
JavaScript does not allow a line end between the return and the expression.

The break statement causes the exit from a loop statement or a switch statement. It?can optionally have a label that will cause an exit from the labeled statement.JavaScript does not allow a line end between the break and the label.

?

An expression statement can either assign values to one or more variables or members, invoke a method, delete a property from an object. The = operator is used for?assignment. Do not confuse it with the === equality operator. The += operator can?add or concatenate.

Expressions

The simplest expressions are a literal value (such as a string or number), a variable, a?built-in value (true, false, null, undefined, NaN,or Infinity), an invocation expression preceded by new, a refinement expression preceded by delete, an expression?wrapped in parentheses, an expression preceded by a prefix operator, or an expression followed by:

? An infix operator and another expression
? The ? ternary operator followed by another expression, then by :, and then by?yet another expression
? An invocation
? A refinement

?

The ? ternary operator takes three operands. If the first operand is truthy, it produces the value of the second operand. But if the first operand is falsy, it produces?the value of the third operand.

?

The operators at the top of the operator precedence list in Table 2-1 have higher precedence. They bind the tightest. The operators at the bottom have the lowest precedence. Parentheses can be used to alter the normal precedence, so:

2 + 3 * 5 === 17 (2 + 3) * 5 === 25

Table 2-1. Operator precedence

. [] ( ) Refinement and invocation delete new typeof + - ! Unary operators * / % Multiplication, division, modulo + - Addition/concatenation, subtraction >= <= > < Inequality === !== Equality && Logical and || Logical or ?: Ternary

The values produced by typeof are 'number', 'string', 'boolean', 'undefined','function', and 'object'. If the operand is an array or null, then the result is?'object', which is wrong. There will be more about typeof in Chapter 6 and?Appendix A.

?

If the operand of ! is truthy, it produces false. Otherwise, it produces true.

The + operator adds or concatenates. If you want it to add, make sure both operands?are numbers.

The / operator can produce a noninteger result even if both operands are integers.
The && operator produces the value of its first operand if the first operand is falsy.Otherwise, it produces the value of the second operand.

The || operator produces the value of its first operand if the first operand is truthy.Otherwise, it produces the value of the second operand.

Invocation causes the execution of a function value. The invocation operator is a pair?of parentheses that follow the function value. The parentheses can contain arguments that will be delivered to the function. There will be much more about functions in Chapter 4.

?

?

A refinement is used to specify a property or element of an object or array. This will?be described in detail in the next chapter.

Literals

Object literals are a convenient notation for specifying new objects. The names of the?properties can be specified as names or as strings. The names are treated as literal?names, not as variable names, so the names of the properties of the object must be?known at compile time. The values of the properties are expressions. There will be?more about object literals in the next chapter.

Array literals are a convenient notation for specifying new arrays. There will be more?about array literals in Chapter 6.

?

There will be more about regular expressions in Chapter 7.

Functions

A function literal defines a function value. It can have an optional name that it can?use to call itself recursively. It can specify a list of parameters that will act as variables initialized by the invocation arguments. The body of the function includes variable definitions and statements. There will be more about functions in Chapter 4.

?

轉載于:https://www.cnblogs.com/ghgyj/p/4001252.html

總結

以上是生活随笔為你收集整理的JavaScript- The Good Parts CHAPTER 2的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 好吊操视频这里只有精品 | 天堂网8 | 国产小视频一区 | 黑人精品欧美一区二区蜜桃 | 欧美男同又粗又长又大 | 热99视频 | 99色| 亚洲精品国产精品国自产网站按摩 | 欧美大片免费观看 | 视频一区二区中文字幕 | 国产精品久久久久91 | 日韩不卡在线 | 青青偷拍视频 | 91精品人妻一区二区三区蜜桃欧美 | 欧美夫妻性生活视频 | 妞干网这里只有精品 | 欧美日韩一区二区三区四区五区 | 伊人网伊人影院 | 青青草伊人网 | 日本精品国产 | 日本欧美久久久 | 精品少妇人妻av一区二区 | 欧美亚一区二区三区 | zzjizzji亚洲日本少妇 | 久久精品99北条麻妃 | av夜夜操 | 亚洲天堂2020 | 日本在线观看一区二区三区 | 亚洲精品福利 | av免费福利| 久久国产秒| 特级做a爱片免费69 少妇第一次交换又紧又爽 亚洲大胆人体 | 亚洲精品1 | 亚洲综合二区 | 日韩3p视频| 国产老头老太作爱视频 | 免费a v网站 | 在线观看毛片网站 | 精品在线你懂的 | 成人欧美激情 | 女生裸体无遮挡 | 日韩中文在线播放 | 久草视频手机在线观看 | 女人做爰全过程免费观看美女 | 蜜桃久久av | 日韩欧美小视频 | 免费高清黄色 | 黄色喷水视频 | 亚洲日本欧美在线 | 亚洲视频福利 | 免费看黄网站在线观看 | 久久久视屏 | 亚洲天堂二区 | 精品欧美一区二区三区免费观看 | 嫩草视频在线观看免费 | 亚洲玖玖玖 | 青青草国产在线视频 | 国产极品美女高潮无套在线观看 | 一级黄色免费网站 | 日韩性插| 少妇偷人精品无码人妻 | proumb性欧美在线观看 | 日本亚洲综合 | 日韩大胆人体 | 日韩色网 | 天天做夜夜做 | av色图 | 一区影视 | 婷婷综合在线视频 | 亚洲一个色 | 男人用嘴添女人下身免费视频 | 宅男av| 中文字幕一二三四区 | 国产精成人 | 中文字幕欧美亚洲 | 欧美婷婷六月丁香综合色 | 免费观看一区二区三区 | 欧美变态口味重另类在线视频 | 亚欧精品视频一区二区三区 | 日韩中文字幕网址 | 中国性老太hd大全69 | 国产精品一区二区电影 | 亚洲色诱 | 成年人在线视频观看 | 九九热色 | 老狼影院伦理片 | 色屁屁一区二区三区视频 | 51吃瓜网今日吃瓜 | 成人毛片视频免费看 | 95视频在线 | 精品国产一区一区二区三亚瑟 | 欧美午夜一区二区 | 超碰97在线免费 | 中文字幕一区二区三区乱码在线 | 亚洲免费片 | 白白色免费视频 | 在线观看成人小视频 | 制服丝袜手机在线 | 亚洲黄色免费观看 |