-
-
Save deepak1556/29126acb41b7b0549f1f to your computer and use it in GitHub Desktop.
notimplemented
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
var _slice = Array.prototype.slice; | |
function Maybe (fn) { | |
return function () { | |
return fn !== void 0 ? fn.apply(this, arguments) : 'Notimplemented' | |
} | |
} | |
function N (f) { | |
var name = f.name; | |
return function (o) { | |
return f.call(this, o) || Maybe(o[name]).call(o,this) | |
} | |
} | |
function type1 (v) { | |
this.v = v; | |
} | |
type1.prototype.equal = N(function equal (o) { | |
if (o instanceof type1) { | |
return this.v === o.v | |
} | |
}) | |
function type2 (v) { | |
this.v = v; | |
} | |
type2.prototype.equal = function equal (o) { | |
if (o instanceof type2) { | |
return this.v === o.v | |
} else if (o instanceof type1) { | |
return this.v === o.v | |
} | |
} | |
a = new type1(1) | |
b = new type2(1) | |
a.equal(b) /=> true / "Not implemented" depending on b has a method equal | |
a.equal(a) /+> true | |
b.equal(b) /=> true | |
b.equal(a) /=> true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment