var i=10;
function a() {
alert(i);
var i = 2;
alert(i);
};
a();
挺经典的一道题,结果出得让人不得不觉得奇怪,想知道是虾米回事,内部到底是怎么执行的。
var i=10;
function a() {
alert(i);
var i = 2;
alert(i);
};
a();
挺经典的一道题,结果出得让人不得不觉得奇怪,想知道是虾米回事,内部到底是怎么执行的。
function Person(){
this.name;
this.age;
this.sex;
this.getName = function(){
return this.name;
}
this.getSex = function(){
return this.sex;
}
this.getAge = function(){
return this.age;
}
}
function Girl(){
this.sex = "female";
this.isSingle = true;
}
Girl.prototype = new Person();
var jessica = new Girl();
jessica.name = "Jessica";
jessica.age = "24";
在面向对象的语言中,使用类来创建一个自定义对象。在JavaScript中一切都可以是对象,用什么办法来创建一个自定义对象?
live()与bind()不同的是一次只能绑定一个事件。
这个方法跟传统的bind很像,区别在于用live来绑定事件会给所有当前以及将来在页面上的元素绑定事件(使用委派的方式)。比如说,如果你给页面上所有的li用live绑定了click事件。那么当在以后增加一个li到这个页面时,对于这个新增加的li,其click事件依然可用。而无需重新给这种新增加的元素绑定事件。
要移除用live绑定的事件,请用die方法
JavaScript: The Definitive Guide, 4th Edition中对Math.ceil(),Math.floor()与Math.round()三个函数的定义。
document.writeln("Math.ceil(4.8992303)输出结果:"+Math.ceil(4.8992303)+"<br/>");
document.writeln("Math.floor(4.8992303)输出结果:"+Math.floor(4.8992303)+"<br/>");
document.writeln("Math.round(4.8992303)输出结果:"+Math.round(4.8992303)+"<br/><br/>");
document.writeln("Math.ceil(4.29993354)输出结果:"+Math.ceil(4.29993354)+"<br/>");
document.writeln("Math.floor(4.29993354)输出结果:"+Math.floor(4.29993354)+"<br/>");
document.writeln("Math.round(4.29993354)输出结果:"+Math.round(4.29993354));

该方法将删除数组的最后一个元素,并把数组长度减1,并且返回它删除的元素的值。如果数组已经为空,则pop()不改变数组,并返回undefined。
arrayObject.pop()