问题描述
- 关于js继承的问题,能帮助一下吗
-
这段代码是在书上看到的,首先创建了一个监听器的父类(function(win){
var _EListener = win.EVentListener = Class.extend({ init : function(){ throw Error("This class must be inherited"); } })
}(window))
然后在另外一个js文件中,创建了一个类来继承它
var _appEventListener = win.AppEventListener = EVentListener.extend({
init : function(){ //代码段 }
});
在运行的时候提示Class 找不到 在查找了一些资料后 ,我将第一段代码修改成了
((function(win){
var _EListener = win.ELisetener = function(){return{init: function(){ throw Error("This class must be inherited"); } }} })(window))
运行时发现 找不到EVentListener
如果想达到想要的效果 应该怎样修改代码? 有前辈能指点一下吗
解决方案
改成下面这样
(function(win){
var _EListener = win.EVentListener = function(){return{
init: function(){
throw Error("This class must be inherited");
}
}}
})(window)
解决方案二:
http://www.cnblogs.com/liyatang/archive/2011/05/30/2062611.html
时间: 2024-09-08 11:51:07