Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- goog.provide("samples.traits");
- goog.provide("samples.traits.HasValue");
- goog.provide("samples.traits.HasValueImpl");
- goog.provide("samples.traits.MyClass");
- goog.require("goog.debug.Logger");
- goog.scope(function() {
- var ns = samples.traits;
- /**
- * An interface for types that have a value
- *
- * @interface
- */
- ns.HasValue = function() {};
- /**
- * @return {string}
- */
- ns.HasValue.prototype.getValue = function() {};
- /**
- * @param {string} value
- */
- ns.HasValue.prototype.setValue = function(value) {};
- /**
- * @implements { samples.traits.HasValue }
- *
- * @constructor
- */
- ns.HasValueImpl = function() {
- };
- /**
- * @type {string}
- */
- ns.HasValueImpl.prototype.value_ = "default";
- /** @inheritDoc */
- ns.HasValueImpl.prototype.getValue = function() {
- return this.value_;
- };
- /** @inheritDoc */
- ns.HasValueImpl.prototype.setValue = function(value) {
- this.value_ = value;
- };
- /**
- * @implements {samples.traits.HasValue}
- *
- * @constructor
- */
- ns.MyClass = function() {
- };
- /** @inheritDoc */
- ns.MyClass.prototype.getValue = function(){};
- /** @inheritDoc */
- ns.MyClass.prototype.setValue = function(value){};
- /**
- * @return {string}
- */
- ns.MyClass.prototype.toString = function() {
- return "myclass: "+this.getValue();
- };
- ns.logger = goog.debug.Logger.getLogger("samples.traits");
- /**
- * @param {samples.traits.HasValue} obj
- */
- ns.verifyType = function(obj) {
- ns.logger.info(obj.getValue());
- ns.logger.info(obj);
- };
- ns.mixin = function(baseObject, traits) {
- for(x = 0; x < traits.length; x++) {
- goog.object.extend(baseObject, traits[x].prototype);
- }
- };
- /**
- * starting point
- */
- ns.start = function(sandbox) {
- var myObject = new ns.MyClass;
- myObject.setValue("first");
- ns.verifyType(myObject);
- ns.mixin(myObject, [ns.HasValueImpl]);
- myObject.setValue("whatup");
- ns.verifyType(myObject);
- };
- goog.exportSymbol("samples.traits.start", ns.start);
- });
Add Comment
Please, Sign In to add comment