Python_day14_ front-end _js-rewrite

Source: Internet
Author: User
Tags object model uppercase character

Description

ECMA (European Computer Manufacturing Association)
?? The ECMA (European Computer Manufacturing Association) defines the ECMA-262 specification. The International Organization for Standardization (ISO/IEC) also adopted ECMAScript as the standard (iso/iec-16262). Since then, Web browsers have struggled (albeit with varying degrees of success and failure) to ECMAScript as the basis for JAVASCRIPT implementations.
?? Although ECMAScript is an important standard, it is not the only part of JavaScript, and certainly not the only one that is standardized. In fact, a complete JavaScript implementation is made up of the following 3 different parts:

   1、核心(ECMAScript)    2、文档对象模型(DOM) Document object model (整合js,css,html)   3、浏览器对象模型(BOM) Broswer object model(整合js和浏览器)

The vast majority of Javascript in development is object-based. It is also object-oriented.

1, JS Introduction 1.1, A brief description of 1.1.1, JavaScript code
    • JavaScript code (or JavaScript only) is a sequence of javascript statements.
1.1.2, JavaScript Combination

JavaScript statements are combined in the form of blocks of code.
?? The block starts with the left curly brace and ends with the closing curly brace.
?? The function of a block is to make the statement sequence execute together.
?? JavaScript functions are a typical example of combining statements in blocks.

1.1.3, JavaScript is sensitive to casing.

?? When writing JavaScript statements, be aware of whether to turn off the case toggle key.
?? The function getElementById is different from the getElementById.
?? Tip: JavaScript is a scripting language. The browser executes the script code on a line-by-row basis when reading the code. For traditional programming, all code is compiled before execution.

1.1.4, notes

?? Single-line comments begin with//.
?? Multiline comments start with/end with/.

1.1.5, variables must start with a letter

?? Variables can also start with the $ and _ symbols (although we do not recommend this)
?? Variable names are case sensitive (Y and y are different variables)
?? Tip: Both JavaScript statements and JavaScript variables are case-sensitive.

??当您向变量分配文本值时,应该用双引号或单引号包围这个值。??当您向变量赋的值是数值时,不要使用引号。如果您用引号包围数值,该值会被作为文本来处理。
1.1.6, semicolon
??分号用于分隔 JavaScript 语句。??通常我们在每条可执行的语句结尾添加分号。??使用分号的另一用处是在一行中编写多条语句。
1.2, variable 1.2.1, variable use
声明(创建) JavaScript 变量var carname;变量赋值  carname="Volvo";例, 标签页需要在script之上    <p id="demo"> test </p>    <script>        var test = " first var js"        document.getElementById(‘demo‘).innerHTML=test    </script>一条语句,多个变量  var name="Gates", age=56, job="CEO";
1.2.2, variable naming rules

1. Camel Marking method
?? The first letter is lowercase, and the next letter begins with an uppercase character. For example:
?? ?? var mytestvalue = 0, Mysecondvalue = "HI";

2. Pascal Marking method
?? The first letter is capitalized, and the next letter begins with an uppercase character. For example:
?? ?? Var mytestvalue = 0, Mysecondvalue = "HI";

3. Hungarian type Marking method
?? Appends a lowercase letter (or a lowercase sequence) to a variable named after the Pascal notation, indicating the type of the variable. For example, I represents an integer and S represents a string, as shown below.
?? ?? Var iMyT1 = 0, smyabs = "HI";

1.2.3, local JavaScript variables
??在 JavaScript 函数内部声明的变量(使用 var)是局部变量,所以只能在函数内部访问它。(该变量的作用域是局部的)。??您可以在不同的函数中使用名称相同的局部变量,因为只有声明过该变量的函数才能识别出该变量。??只要函数运行完毕,本地变量就会被删除。
1.2.4, Global JavaScript variables
??在函数外声明的变量是全局变量,网页上的所有脚本和函数都能访问它。
Lifetime of 1.2.5, JavaScript variables
??JavaScript 变量的生命期从它们被声明的时间开始。??局部变量会在函数运行以后被删除。??全局变量会在页面关闭后被删除。
1.3. Character type

String, number, Boolean, array, object, Null, Undefined

1.3.1, JavaScript arrays

?? var cars=new Array ("Audi", "BMW", "Volvo"); #下标从0开始

1.3.2, Integral type

?? What is the exact range of the expression?-9007199254740992 (-253) to 9007199254740992 (253)

1.3.3, floating-point

?? For example 1.1 1.2 or 4.1E22 = 4.1 * 1022
?? 16 binary and 8 decimal expressions
?? 16 binary data front plus 0x, octal front plus 0
?? 16 binary numbers are made up of 16 characters, such as 0-9,a-f
?? 8 binary number consists of 0-7 and 8 digits
?? 16 binary and 8 binary and 2 binary conversion

1.3.4, Boolean

?? There can be only two values: TRUE or FALSE.

1.3.5, Null & Undefined

?? The Undefined type has only one value, which is Undefined. When the declared variable is not initialized, the default value of the variable is undefined.
?? Undefined are actually derived from value null, so ECMAScript define them as equal.
?? Although the two values are equal, they have different meanings. A undefined is a value that is assigned to a variable when it is declared but not initialized, and null is used to represent an object that does not already exist.
?? If the function or method is to return an object, the object returned is usually null when it is not found.

1.3.6, type query function (typeof)

?? ECMAScript provides the typeof operator to determine whether a value is within a certain type of range. You can use this operator to determine whether a value represents an original type: if it is the original type, you can also determine which primitive type it represents.

    var nNum=1111    var sStr="abcc"    var bBom=true    var fh=nNum+bBom    var fh2=sStr+bBom    var fh3=nNum+sStr    var fh4=bBom+bBom    console.log("数字: "+typeof (nNum))     数字: number    console.log("字符串: "+typeof (sStr))    字符串: string    console.log("布尔值: "+ typeof (bBom))  布尔值: boolean    console.log("fh: "+typeof (fh))           fh: number    console.log("fh2: "+typeof (fh2))     fh2: string    console.log("fh3: "+typeof (fh3))     fh3: string    console.log("fh4: "+typeof (fh4))     fh4: number
1.3.7, logical AND operator (&&)
逻辑 AND 运算的运算数可以是任何类型的,不止是 Boolean 值。如果某个运算数不是原始的 Boolean 型值,逻辑 AND 运算并不一定返回 Boolean 值:如果某个运算数是 null,返回 null。 如果某个运算数是 NaN,返回 NaN。 如果某个运算数是 undefined,返回undefined。 例一var na=NaN;        var nb=1233;    var nc=3333;    console.log(na&&nb);      //NaN    console.log(nb&&nc);     //3333例二    && and    # 两个值都必须一样才是true    || or     # 只有一个值为true 那就是true,    !  not    # 不等于    var x = 3;    var y = 5;    var z = 10    if (x > y || z > y){        document.write(‘yes‘)    }else {        document.write(‘no‘)    }     # 结果为真  yes
1.3.8, objects

?? Objects are separated by curly braces. Inside the parentheses, the properties of the object are defined in the form of name and value pairs (name:value). Attributes are separated by commas: example

All things in JavaScript are objects: strings, numbers, arrays, dates, and so on.
?? In JavaScript, objects are data that owns properties and methods.

1.3.9, properties, and methods

?? A property is a value associated with an object.
?? Method is an action that can be performed on an object.

1.3.9.1, accessing an object's properties

1、访问对象属性的语法是:objectName.propertyName    var message = "hello world!";    var x = message.length;    alert(x)    length就是message的属性了 长度为122、访问对象的方法objectName.methodName()    var message = "hello world!";    var y = message.toUpperCase()    alert(y)    toUpperCase就是message的方法了,全都转成大写 结果为 HELLO WORLD 提示:在面向对象的语言中,使用 camel-case 标记法的函数是很常见的。您会经常看到 someMethod() 这样的函数名,而不是 some_method()。
1.3.10, scope

?? Scope refers to the scope of the variable to be applied.
?? Scopes are divided into public, private, and protected scopes

?? Object properties in a common scope can be accessed from outside the object, where the developer creates an instance of the object, and then uses its common properties;
?? Properties in a private scope can only be accessed inside the object,
?? ECMAScript only the common scope of the proposed workaround: The attribute is underlined before and after the property is a private scope
?? Note that underlining does not change the fact that a property is a common property, it simply tells other developers that the attribute should be considered private.

1.3.11, keyword this

?? One of the most important concepts to master in ECMAScript is the use of the keyword this, which is used in the object's methods. The keyword this always points to the object that called the method, for example:

<script type="text/javascript">    var oac = new Object();    oac.color = "red";    oac.showColor = function () {        alert(this.color)    }    oac.showColor()</script>    # 输出red 关键字 this 用在对象的 showColor() 方法中。在此环境中,this 等于 oac 。下面的代码与上面的代码的功能相同:<script type="text/javascript">    var oac = new Object();    oac.color = "red";    oac.showColor = function () {        alert(oac.color)    }    oac.showColor()</script>

1.13.11.1, reasons for using this
?? Why use this? Because when instantiating an object, it is always impossible to determine what variable name the developer will use. Use this to reuse the same function in any number of places

<script>    function showColor() {        alert(this.color);    };    var oCar1 = new Object;    oCar1.color = "red";    oCar1.showColor = showColor;    var oCar2 = new Object;    oCar2.color = "blue";    oCar2.showColor = showColor;    oCar1.showColor();      //输出 "red"    oCar2.showColor();      //输出 "blue"</script>注意,引用对象的属性时,必须使用 this 关键字
1.3.12, constructor mode

?? Creating a constructor is as easy as creating a factory function. The first step is to select the class name, which is the name of the constructor. According to convention, the first letter of the name is capitalized so that it is separated from the name of the variable whose first letter is usually lowercase. In addition to this, the constructor looks much like a factory function.

<script>    function Car(a1,b1,c1) {        this.color = a1;        this.doors = b1;        this.mpg = c1;        this.showColor = function () {            document.write(this.color);            document.write(this.doors);            document.write(this.mpg);        };    }    var oCar1 = new Car("red");    var oCar2 = new Car("yellow",22,232);    oCar1.showColor();    document.write(‘<br />‘)    oCar2.showColor()</script>

Instead of creating an object within the constructor, the This keyword is used. When you use the new operator to construct a function, an object is created before the first line of code is executed, and only this is used to access the object. You can then give the this property directly, which by default is the return value of the constructor (you do not have to explicitly use the return operator),

Python_day14_ front-end _js-rewrite

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.