您的位置:首页 > Web前端 > JavaScript

JS总结2--(方法和函数)

2010-09-01 14:33 316 查看
三、继承的实现

function Person(name)

{

this.Name = name;

this.sayName = funtcion()

{

alert(this.name);

}

}

function myPerson(name,age)

{

Person.call(this,name); //或 Person.apply(this,new Array(name));

this.Age = age;

this.sayAge = function()

{

alert(this.name);

}

this.say = function()

{

alert(this.Name + "|" + this.Age);

}

}

var a = new myPerson("张三",25);

a.sayName();

a.sayAge()

a.say();

二、获取对象属性个数

Object.prototype.count = (Object.prototype.hasOwnProperty("__count__")) ? function()

{

return this.__count__;

}:function()

{

var count=0;

for(var i in this) if(this.hasOwnProperty(i))

{

count++;

return count;

};

}

var myobj = {

name1:"value1",

name2:"value2"

}

alert(myobj.count());

三、 滚到底触发事件

$(window).bind("sroll",function(){

if($(window).height() + $(document).scrollTop() >= $(document).height())

{

alert("到底了!");

}

});
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: