Created
July 27, 2012 18:05
-
-
Save suzuki0keiichi/3189431 to your computer and use it in GitHub Desktop.
ここまでやるとClosure Compilerでtraitでmix-in的なことをしつつ--jscomp_error=checkTypesをつけても怒られなくなるけどそれ以外方法無いの?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
hoge = {}; | |
/** @interface */ | |
hoge.Interface1 = function(){}; | |
/** @interface */ | |
hoge.Interface2 = function(){}; | |
/** | |
* @function | |
* @param {number} num | |
*/ | |
hoge.Interface1.prototype.method1; | |
// interfaceに実装があると怒られるの回避 | |
(function() { | |
var p = hoge.Interface1.prototype; | |
p.method1 = function(num) { alert("base method1 " + num); }; | |
})(); | |
/** | |
* @function | |
* @param {number} num | |
*/ | |
hoge.Interface2.prototype.method2; | |
// interfaceに実装があると怒られるの回避 | |
(function() { | |
var p = hoge.Interface2.prototype; | |
p.method2 = function(num) { alert("base method2 " + num); }; | |
})(); | |
/** | |
* @constructor | |
*/ | |
hoge.Class1 = function(){ | |
}; | |
/** @function */ | |
hoge.Class1.prototype.method3 = function() { alert("base method3"); } | |
/** | |
* @constructor | |
* @extends {hoge.Class1} | |
* @implements {hoge.Interface1} | |
* @implements {hoge.Interface2} | |
*/ | |
hoge.Class2 = function(){ | |
}; | |
hoge.Class2.prototype = new hoge.Class1(); | |
/** @override */ | |
hoge.Class2.prototype.method1 = function(num){ | |
alert("overridden method1 " + num); | |
}; | |
// interface実装classに実装がないと怒られるの回避 | |
hoge.Class2.prototype.method2 = hoge.Interface2.prototype.method2; | |
/** @type {hoge.Class2} */ | |
var c2 = new hoge.Class2(); | |
c2.method1(10); // overridden | |
c2.method2(20); // base | |
c2.method3(); // base |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment