部分源代码如下:
define(function(require) {
var Util = require('./util');
var Object = function() {
this.constructor(); //this.constructor()是干什么的
};
Object.prototype = {
constructor : function() {
//此处为什么不使用Object呢
},
constructed : function() {
},
callParent : function() {
var method = this.callParent.caller; //?????
if (!method.$owner) {
method = method.caller;
}
var parentClass = method.$owner.superclass, methodName = method.$name;
return parentClass[methodName].apply(this, arguments);
}
};
//some code here
}
说明:这里的代码是某个平台的关于控件的定义的源代码,该平台在web开发中实现了控件的拖拽功能,其中控件是以继承方式设计的。这个是简单的介绍,下面是要向大家请教的问题,
问题一:
在权威指南中关于constructor属性是这样介绍的
var F=function(){}
var p=F.prototype;
var c=p.constructor;
c===F
这个很好理解
var Object = function() {
this.constructor();
};
在构造函数Object中添加的this.constructor()是干什么的
问题二:
Object.prototype.constructor=function(){}而不是Objectprototype.constructor=Object;
这2者有什么区别
问题三:
mdn上关于caller的说明如下
如果一个函数f是在全局作用域内被调用的,则f.caller为null,相反,如果一个函数是在另外一个函数作用域内被调用的,则f.caller指向调用它的那个函数.
如果实例化一个Object对象,并让这个对象调用callParent方法,那么method指向的是Object类的parent方法吗
以上是我的问题,希望各位热心的大佬能解答下我的疑惑,或者给出我在哪些知识上面还有所欠缺,我自己去研究,先谢谢各位了,顺便祝看到此贴的周末愉快。
http://www.blogjava.net/heavensay/archive/2013/10/20/405440.html