搜索

关于JS预解析一道题

1009

var i=10;
function a() {
    alert(i);
    var i = 2;
    alert(i);
};
a();

挺经典的一道题,结果出得让人不得不觉得奇怪,想知道是虾米回事,内部到底是怎么执行的。

继续阅读»

[每日一练]面向对象JavaScript继承例子一

0714


	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 vs bind

0418

live()与bind()不同的是一次只能绑定一个事件。

这个方法跟传统的bind很像,区别在于用live来绑定事件会给所有当前以及将来在页面上的元素绑定事件(使用委派的方式)。比如说,如果你给页面上所有的li用live绑定了click事件。那么当在以后增加一个li到这个页面时,对于这个新增加的li,其click事件依然可用。而无需重新给这种新增加的元素绑定事件。

要移除用live绑定的事件,请用die方法

继续阅读»

用Jquery玩玩Font

0709

Ashung给我看他的08年写的一个”web font v 0.3“的页面,偶也用jquery小玩了一下,嘿嘿,在线演示

web font

继续阅读»

JS:Math.ceil(),Math.floor()与Math.round()

0620

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));

继续阅读»

JS:Array的pop,push,unshift,shift

0619

js的array:pop,push,shift,unshift

pop()

定义

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

语法

arrayObject.pop()

继续阅读»