Permalink
Browse files

* datatype.js: basic stuff working

  • Loading branch information...
1 parent de1c5c0 commit ad64eb2b2d888ca5766b9943e50ea82e2d46c96f David Nolen committed May 18, 2010
Showing with 31 additions and 6 deletions.
  1. +31 −6 datatype.js
View
@@ -1,11 +1,36 @@
_.mixin({
+ extenderOf: function(x, protocol) {
+ return _(x.protocols).indexOf(protocol) != -1;
+ },
+
+ protocol: function(obj) {
+ obj.toString = function() {
+ return ["<Protocol: ", (obj.name || "Unnamed protocol"), ">"].join("");
+ };
+ return obj;
+ },
+
datatype: function(obj) {
- var klass = function() {};
- _(obj).chain()
- .filter(_.isFunction)
- .each(function(fn, k) {
- console.log(fn, k);
- }).value();
+ var klass = function() {
+ if(_.isFunction(this.initialize)) {
+ return this.initialize.apply(this, arguments);
+ } else {
+ return this;
+ }
+ };
+ var methodMap = obj.protocols
+ .map(function(x) { x = _(x).clone(); delete x.name; delete x.toString; return x; });
+ obj =_.reduce((methodMap || []).concat(obj), {}, function(memo, m) {
+ return _.extend(memo, m);
+ });
+ obj = _(obj).extend({
+ toString: function() {
+ return ["<Type: ", this.name, ">"].join("");
+ }
+ });
+ klass.prototype = obj;
+ klass.prototype.type = klass;
+ klass.prototype.protocols = klass.protocols = obj.protocols;
return klass;
}
});

0 comments on commit ad64eb2

Please sign in to comment.