脚本宝典收集整理的这篇文章主要介绍了javascript代码实例教程-JavaScript学习小结,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。小宝典致力于为广大程序猿(媛)提供高品质的代码服务,请大家多多光顾小站,小宝典在此谢过。
学习目的:
1.Web相关开发越来越流行,学习JS十分有必要
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 构造函数实现的。
[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();
觉得可用,就经常来吧! 脚本宝典 欢迎评论哦! js脚本,巧夺天工,精雕玉琢。小宝典献丑了!
以上是脚本宝典为你收集整理的javascript代码实例教程-JavaScript学习小结全部内容,希望文章能够帮你解决javascript代码实例教程-JavaScript学习小结所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。