请考虑以下代码.
function a() {}
function b() {}
function c() {}
b.prototype = new a();
c.prototype = new b();
console.log((new a()).constructor); //a()
console.log((new b()).constructor); //a()
console.log((new c()).constructor); //a()
Run Code Online (Sandbox Code Playgroud)
此外,请考虑以下内容.
console.log(new a() instanceof a); //true
console.log(new b() instanceof b); //true
console.log(new c() instanceof c); //true
Run Code Online (Sandbox Code Playgroud)
(new c()).constructor等于a()和Object.getPrototypeOf(new c())是a{ },怎么可能instanceof知道这new c()是一个实例c?我在javascript中使用模块模式.它是一种创建"类"实例的方法吗?我正在以正确的方式使用它?
var moduleClass = (function () {
var a =5;
return {
getA: function () {
console.log(a);
}
};
})();
var instance = moduleClass;
instance.getA();
Run Code Online (Sandbox Code Playgroud)
http://jsfiddle.net/PzLKy/ 如何在新实例上传递参数?