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

JavaScript对象学习笔记

2010-03-02 23:09 501 查看
参考文章 /article/4676562.html

//function User(name) {

// this.name = name;
//}

//User.prototype.getname = function() {

// return this.name;
//}

//var user = new User('Zhang San');

//alert(user.constructor === User) //true

//alert(user.constructor.prototype === User.prototype)//true

//alert({}.constructor === Object) //true

//alert([].constructor === Array) //true

//alert(''.constructor === String)//true

//alert(user.constructor.prototype.constructor);//User

function Person(sex) {

this.sex = sex;
}

function User(name) {

this.name = name;
}

User.prototype = new Person('man');

var user = new User('Zhang San');

//alert(user.sex); //'man'

//alert(user.constructor);//Person

//alert(User.prototype.constructor); //Person

//Array.prototype.max = function() {
// var maxValue = this[0];

// for (var i = 1; i < this.length; i++) {

// maxValue = this[i];
// }
// return maxValue;

//}

//alert([2, 33, 25].max());//25

Array.prototype = {

max: function() {
var maxValue = this[0];

for (var i = 1; i < this.length; i++) {

maxValue = this[i];
}
return maxValue;
}

};

alert([2, 33, 25].max());//因为Array.prototype是只读的
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: