Poetro wrote:
> Have you looked at http://json-schema.org/? There are various
> implementations of it at http://json-schema.org/implementations.html
That looks like much more than what npup is doing. In fact, for my
uses it seems over the top. I understand that it might make for a
useful contract between differing parties, but internal to my
application it definitely seems like overkill.
In my local function, I really want to avoid code like this:
if (obj.prop1 && typeof obj.prop1 === "number" && obj.prop1 > 0) {
if (obj.func1 && typeof obj.func1 === "function") {
var results = obj.func1();
// ...
}
}
npup's suggestion might let me do this instead:
if (Acts.As(mySpec, obj)) {
var results = obj.func1();
}
and a fairly simple currying enhancement might allow something like
var myTest = Acts.As(mySpec);
// ...
if (myTest(obj)) {
var results = obj.func1();
}
This is exactly duck-typing at a granular level.
-- Scott
--
To view archived discussions from the original JSMentors Mailman list:
http://www.mail-archive.com/[email protected]/
To search via a non-Google archive, visit here:
http://www.mail-archive.com/[email protected]/
To unsubscribe from this group, send email to
[email protected]