Возможно, я не понимаю ваш вопрос, но это то, чего вы хотите достичь?
// Static class method.
Interface.ensureImplements = function(object) {
if(arguments.length < 2) {
throw new Error("Function Interface.ensureImplements called with " +
arguments.length + " arguments, but expected at least 2.");
}
for(var i = 1, len = arguments.length; i < len; i++) {
var interface = arguments[i];
if(interface.constructor !== Interface) {
throw new Error("Function Interface.ensureImplements expects arguments"
+ " two and above to be instances of Interface.");
}
for(var j = 0, methodsLen = interface.methods.length; j < methodsLen; j++) {
var method = interface.methods[j];
if(!object[method] || typeof object[method] !== 'function') {
throw new Error("Function Interface.ensureImplements: object "
+ "does not implement the " + interface.name
+ " interface. Method " + method + " was not found.");
}
}
}
};
Этот код используется для проверки, является ли функция типом интерфейса. Ключевой код:
if(interface.constructor !== Interface) {
Для распространяется на класс, который вы можете сделать это:
function Item() {
};
function Picture() {
Item.call(this); // Call to superClass constructor with subclass instance
};
Picture.prototype = new Item();
Picture.prototype.constructor = Picture;
var picture = new Picture();
if(picture instanceof Item){
alert("True");
} else {
alert(false);
}
подклассов уроженцы является проблематичным. Посмотрите на [эту статью] (http://speakingjs.com/es5/ch28.html) или другие там. Возможно, это возможно с ECMA6, но я не рассматривал это. – hon2a