JavaScript學習小結

來源:互聯網
上載者:User

學習目的:
1.Web相關開發越來越流行,學習JS十分有必要

2.多學習一種語言,想多瞭解一種語言的文化內涵

3.認識一下指令碼語言,之前一直學習C,C++,換換口味

 


學習途徑:
1.之前實習期間的項目積累

2.互連網的各種零碎的資料

3.codecademy的線上Js教學課程(冗長細緻的課程,打字打到手抽筋)

4.各種書本,如《headfirst Js》等

 


零星的感受:(一直在補充)

1.js中類的屬性,可以使用.也可以使用["xx"]來標識


2.JS也有封裝,在類的建構函式中使用 var來定義屬性或者方法而不是this


3.Js的函數定義之後沒有分好,但是變數定義之後有分號。


4.函數和類中的this不能省略


5.Js的執行個體化是通過 new 建構函式實現的。

function Person(name,age) {

[javascript]
 this.name = name; 
  this.age = age; 

// Let's make bob and susan again, using our constructor  
var bob = new Person("Bob Smith", 30); 

  this.name = name;
  this.age = age;
}
// Let's make bob and susan again, using our constructor
var bob = new Person("Bob Smith", 30);6.使用prototype使得每個執行個體都有這個屬性,也實現了繼承
[javascript]
// the original Animal class and sayName method  
function Animal(name, numLegs) { 
    this.name = name; 
    this.numLegs = numLegs; 

Animal.prototype.sayName = function() { 
    console.log("Hi my name is "+this.name); 
}; 
 
// define a Penguin class  
function Penguin(name, numLegs) { 
    this.name = name; 
    this.numLegs = 2; 

 
// set its prototype to be a new instance of Animal  
Penguin.prototype = new Animal(); 
 
var penguin = new Penguin("Gigi"); 
penguin.sayName(); 

// the original Animal class and sayName method
function Animal(name, numLegs) {
    this.name = name;
    this.numLegs = numLegs;
}
Animal.prototype.sayName = function() {
    console.log("Hi my name is "+this.name);
};

// define a Penguin class
function Penguin(name, numLegs) {
    this.name = name;
    this.numLegs = 2;
}

// set its prototype to be a new instance of Animal
Penguin.prototype = new Animal();

var penguin = new Penguin("Gigi");
penguin.sayName();

 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.