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是只读的
//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是只读的
相关文章推荐
- JavaScript学习笔记--第四章.框架间对象的调用
- javascript 学习笔记(八)javascript对象
- Javascript学习笔记(对象)
- JavaScript高级程序设计-学习笔记4(创建对象)
- JavaScript学习笔记之JS对象
- JavaScript学习笔记之对象及继承
- Javascript学习笔记-----对象
- JavaScript高级程序设计(第3版)学习笔记11 内建js对象
- HTML5学习笔记(二十):JavaScript中的标准对象
- JavaScript学习笔记(09)之文档对象模型DOM
- JavaScript学习笔记之浅析几种创建对象的方法
- javascript之对象学习笔记(二)--对象原型,继承
- JavaScript 学习笔记 (2) - 对象的三个重要概念
- JavaScript学习笔记:(window对象)
- 零基础入门-javaScript学习笔记之对象和不一样的this
- JavaScript--基于对象的脚本语言学习笔记(一)
- JavaScript学习笔记5--对象
- JavaScript学习笔记之原型对象
- JavaScript学习笔记——DOM_对document对象的内容、属性、样式的操作
- JavaScript 学习笔记七 定义对象