Chromium Code Reviews| Index: third_party/closure_compiler/tests/getInstance_test.js |
| diff --git a/third_party/closure_compiler/tests/getInstance_test.js b/third_party/closure_compiler/tests/getInstance_test.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..66af82e9483140f2257c78646d668fe024c6b518 |
| --- /dev/null |
| +++ b/third_party/closure_compiler/tests/getInstance_test.js |
| @@ -0,0 +1,48 @@ |
| +var cr = {}; |
| +var myModule = {}; |
| + |
| +myModule.Mess = function() {}; |
| +myModule.Mess.prototype = { |
| + whatever: function() {} |
| +}; |
|
Dan Beam
2014/07/29 18:05:12
^ unused
Vitaly Pavlenko
2014/07/29 18:53:46
Acknowledged.
|
| + |
| +/** |
| + * @constructor |
| + */ |
| +myModule.myBaseClass = function() {}; |
| + |
| +myModule.myBaseClass.prototype = { |
| + /** |
| + * @param {number} name |
| + */ |
| + myMethod: function(name) { |
| + alert(name); |
| + } |
| +}; |
| + |
| +/** |
| + * @constructor |
| + * @extends {myModule.myBaseClass} |
| + */ |
| +myModule.myClass = function() {}; |
| + |
| +/** |
| + * @param {!Function} ctor |
| + */ |
| +cr.addSingletonGetter = function(ctor) { |
|
Dan Beam
2014/07/29 18:05:12
can this file be:
var cr = {
/** @param {!Funct
Vitaly Pavlenko
2014/07/29 18:53:46
Done.
|
| + ctor.getInstance = function() { |
| + return ctor.instance_ || (ctor.instance_ = new ctor()); |
| + }; |
| +}; |
| + |
| +cr.addSingletonGetter(myModule.myClass); |
| + |
| +/** |
| + * @param {string} name |
| + */ |
| +myModule.myClass.myMethod = function(name) { |
| + myModule.myClass.getInstance().whatever(); |
| + myModule.myClass.getInstance().myMethod(name); |
| +}; |
| + |
| +myModule.myClass.myMethod('string'); |