/**
* @description 接口验证
* @param {Object}
* imp //实现类
* @param {Object}
* _interface 实现的接口 格式:['xx','yy']
* @example: var in_catDAO = ['eat', 'sleep'];
*
* function im_CatDAO(){
this.setName = function(){
alert('this is set name');
}
this.getName = function(){
alert('this is get name');
}
$Implement(this,in_CatDAO);//接口验证
return this;
}
}
*/
/**
* @description 接口验证
* @param {Object} imp //实现类
* @param {Object} _interface 实现的接口
*/
function $Implement(imp, _interface){
for (need in _interface) {
var methodExists = false; // 单一方法
for (method in imp) {
if (_interface[need] == method) {
methodExists = true;
break;
}
}
if (methodExists == false) {
alert("method:" + _interface[need] + "() doesn't exist!");
throw new Error("method:" + _interface[need] + "() doesn't exist!");// 抛出异常
}
}
}