Get familiar with JavaScript

來源:互聯網
上載者:User

The core JavaScript language definies a minimal API for working with text, arrays, dates, and regular expressions but does not include any input or output functionality.
Input and output (as well as more sophisticated features, such as networking, storage, and graphics) are the responsibility of the "host environment" withiin which JavaScript is embeded.
Usually that host envrionment is a web browser. Browser-based APIs loosely known as "client-side JavaScript".

JavaScript離不開庫的支援,這也就是為什麼JQuerry庫和JS如此緊密綁定。當然你也可以選用別的庫,但是無可否認JQurry是最火的。

 

JavaScript is an object-oriented language. but it is quite different than most.

JavaScript的物件導向特性需要用閉包的概念來類比,這個稍後會有專門文章進行介紹。

 

The JavaScript interpreter performs automatic garbage collection for memory management. This means that a program can create objects as needed, and the programmer never needs to worrry about destruction or deallocation fo the those objects.

 

Variables are declared with the "var" keyword. JavaScript variables are untyped: you can assign a value of any type to a variable, and you can later assign a value of a different type to the same variable.

 

JavaScript does not have "block scope". It uses "functuion scope".
function scope: variables are visible within the function in which they are defined and within any functions that are nested within that function. Curiously, this means that variables are even visible before they are declared. Although the local variable
is defined throughout, it is not actually initialized until the var statement is executed.

 

JavaScript的簡單類型包括數字,字串,布爾值,null值和undefined值。其他所有的值都是對象。數字,字串和布爾值“貌似”對象,因為它們擁有方法

,但它們是不可變的。JavaScript中的對象是可變的鍵控集合(keyed collections)。在JavaScript中,數組是對象,函數是對象,Regex是對

象,當然,對象自然也是對象。
Objects:
object.property       -->(property) identifier which is static and must be hardcoded in the program
object["property"]    -->("property") the name of the property is expressed as a string, which can be manipulated and created while a program is running.
對象是屬性的容器,其中每個屬性都擁有名字和值。屬性的名字可以是包括Null 字元串在內的任一字元串。屬性值可以是除undefined值之外的任何值。

Suppose you assign to the property x of the object o. If o already has an own(noninherited) property named x, then the assignment simply changes the value of this existing property. Otherwise, the assignment creates a new property named x on the object o.
If o previously inherithed the property x, that inherited property is now hidden by the newly created own property with the same name.

The inheritance occurs when querying properties but not when when setting them is a key feature of JavaScript. This allows us to selectively override inherited properties.

 

closure(閉包的概念)
函數可以被定義在其他函數中。一個內建函式自然可以訪問自己的參數和變數,同時它也能方便地訪問它被嵌套在其中的那個函數的參數與變數。通過函數字面量(非 new Function。。。的方式)建立的函數對象包含一個連到外部內容的串連。這被稱為閉包。它是JavaScript強大表現力的根基

JavaScript uses lexical scoping. This means that functions are executed using the variable scope that was in effect when they were defined, not the variable scope that is in effect when they are invoked.

Each time a JavaScript function is invoked, a new object is created to hold the local variables for that invocation, and that object is added to the scope chain.

 

When nested, however, function declarations may only appear at the top level of the function they are nested within. function defintion expressions may appear anywhere in you JavaScript code.

(var name = function declaration)

 

除了聲明時定義的形式參數,每個函數接受兩個附加的參數:this和arguments
方法調用模式
當一個函數被儲存為對象的一個屬性時,我們稱它為一個方法。當一個方法被調用時,this被綁定到該對象。
函數調用模式
當一個函數並非一個對象的屬性時,那麼它被當做一個函數來調用。this被綁定到全域對象。 例如:
var sum = add(3, 4);

構造器調用模式
如果在一個函數前面帶上new來調用,那麼將建立一個隱藏串連到該函數對象的prototype成員的新對象,同時this將會被綁定到那個新對象上。
Apply調用模式
apply方法允許靜態調用函數,並允許我們選擇this的值。
apply方法接收兩個參數。第一個是將被綁定給this的值。第二個就是一個參數數組。

 

 

 

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.