码迷,mamicode.com
首页 > 编程语言 > 详细

JavaScript初步

时间:2018-02-02 21:55:16      阅读:170      评论:0      收藏:0      [点我收藏+]

标签:使用   定义   ati   就是   string   数据   实例   方式   div   

1.JavaScript定义函数时需要使用function关键字修饰
2.同一个js文件中的方法,后出现的方法会覆盖之前的方法如下代码输出2\n2,也就是说在开始执行文件前,第二个方法已经覆盖了第一个方法。
<script>
function my_func(){
document.write(1);
}

my_func()

document.write("<br>");

function my_func(){
document.write(2);
}

my_func()
</script>
3.JavaScript中我们将鼠标或者热键的动作称之为事件,由鼠标或者热键引起的一些列程序动作称之为事件驱动,对时间进行处理的程序或者函数我们称之为事件处理程序
4.JavaScript事件参考手册(http://www.w3school.com.cn/jsref/jsref_events.asp)
5.JavaScript的所有数据都可以被视为对象,而每个对象都有其属性和方法。对象的属性是反映对象某些特定的性质的,对象的方法能对该对象做一些事情。
6.JavaScript创建对象的方式:
1.通过new Object()来创建
student = new Object(); // 创建对象“student”
student.name = "Tom"; // 对象属性 名字
student.age = "19"; // 对象属性 年龄
student.study =function() { // 对象方法 学习
alert("studying");
};
student.eat =function() { // 对象方法 吃
alert("eating");
};
比较区别于java等其他语言的创建,可以看到,JavaScript对象的创建十分灵活,所有的属性和方法可以在对象实例化以后追加
2.
var student = {};
student.name = "Tom";
3.
var student = {
name:"Tom";
age:"19";
}
4.通过function关键字创建
function student(name,age) {
this.name = name;
this.age = age;
this.study = function() {
alert("studying");
};
this.eat = function() {
alert("eating");
}
}
这里可以看出,JavaScript对于对象的创建和方法使用的是相通的关键字,其实例化方式如下
var student1 = new student(‘Tom‘,‘19‘);
var student2 = new student(‘Jack‘,‘20‘);
5.其方法的或属性的调用也是通过类似于java的点的方式实现
还可以使用with关键字实现方法属性的调用
with(student1) {
var x = name;
var y= age;
study();
eat();
}
6.常用内置对象:以上三个类所包含的方法
String(http://www.w3school.com.cn/jsref/jsref_obj_string.asp)
Math(http://www.w3school.com.cn/jsref/jsref_obj_math.asp)
Array(http://www.w3school.com.cn/jsref/jsref_obj_array.asp)

JavaScript初步

标签:使用   定义   ati   就是   string   数据   实例   方式   div   

原文地址:https://www.cnblogs.com/Jason-MLiu/p/8406883.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!