写了一段测试代码
还是没弄明白
求指点...//两种创建新对象的函数
Object.f1 = function(o) {
var F = function() {};
F.prototype = o;
return new F();
};Object.f2 = function(o) {
var newObject = {};
newObject.prototype = o;
return newObject;
};//创建原始对象
var o = { x:"o_x", y:"o_y" };//通过三种不同方法创建新对象
var o_f0 = o;
var o_f1 = Object.f1(o);
var o_f2 = Object.f2(o);//改写对象属性
o.x = "f0.x2";
o_f1.x = "f1.x2";
o_f2.x = "f2.x2";//分组显示对象的属性和方法
console.group("f0");
console.dir(o_f0);
console.groupEnd("f0");console.group("f1");
console.dir(o_f1);
console.groupEnd("f1");console.group("f2");
console.dir(o_f2);
console.groupEnd("f2");firebug测试结果:
还是没弄明白
求指点...//两种创建新对象的函数
Object.f1 = function(o) {
var F = function() {};
F.prototype = o;
return new F();
};Object.f2 = function(o) {
var newObject = {};
newObject.prototype = o;
return newObject;
};//创建原始对象
var o = { x:"o_x", y:"o_y" };//通过三种不同方法创建新对象
var o_f0 = o;
var o_f1 = Object.f1(o);
var o_f2 = Object.f2(o);//改写对象属性
o.x = "f0.x2";
o_f1.x = "f1.x2";
o_f2.x = "f2.x2";//分组显示对象的属性和方法
console.group("f0");
console.dir(o_f0);
console.groupEnd("f0");console.group("f1");
console.dir(o_f1);
console.groupEnd("f1");console.group("f2");
console.dir(o_f2);
console.groupEnd("f2");firebug测试结果:
解决方案 »
- 鼠标监听事件的问题
- 求助,以下代码是实现漂浮窗口功能,但不能实现关闭
- 从绝对文件路径解析文件名
- 谁能告诉我第二次document.getElementById为什么得不到对象了?
- 用JS怎么实现按键盘上的某个键?
- js在ie下不支持getAttribute("class"),不应该呀。
- 求助 : 关于iframe的缓存问题
- 关于日期格式(yyyy/mm/dd)的一个问题 急在线等
- 怎么做?---关闭子窗口同时提交父窗口表单
- 有办法得到一个对象的属性列表吗?比如<tr width='95%' height='20' ...>中width,height...
- 关于js的call方法问题
- GridPanel的某一列嵌入 checkbox
在看看 prototype 是什么意思
__proto__:构造函数原型
仔细读一下上面的字,意思就明白的差不多了。
function Person(){
}
var p = new Person();
alert(p.constructor.prototype==p.__proto__);
因为p实例的构造函数是Person,所以p.constructor.prototype会等于p.__proto__。
个人认为__proto__类似constructor.prototype的简写。