您好,欢迎访问一九零五行业门户网

JavaScript学习小结

学习目的:
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();
其它类似信息

推荐信息