On Mon, Mar 28, 2011 at 12:56 PM, Nick Morgan <skilldr...@gmail.com> wrote:

> On 28 March 2011 00:40, Olov Lassus <olov.las...@gmail.com> wrote:
>
> > 2. + < <= >= >
> >   are restricted to primitive strings or numbers
> >   (but never a mix)
>
>
> I don't see how you're enforcing this. What about:
>
> function foo(x) {
>   return x < 5;
> }
>
> If foo is called without an argument x is undefined. This is a silly
> example, but there are lots of cases where the type of a variable
> can't be statically determined (which almost goes without saying, as
> JS is dynamically typed). How do you ensure/check that the correct
> types are used?
>

He's not deriving it statically. He uses narcissus to build a parse tree to
find operators (and such). He then rewrites those operators and whatever to
test functions he wrote (simply wrapping the entire sub-expressions). (From
the top of my head, it looks sound, but I'm not very certain about that.)
 He then evals/injects the resulting code which uses a mini test framework
to determine during runtime whether the demanded typing matches.

Eg. it's (probably) not meant for production, only your testing (or possibly
development) phase. Which, like unit testing, puts the burden on your tests.

Personally I'd never use it. But I'm sure some might be interested.

- peter

-- 
To view archived discussions from the original JSMentors Mailman list: 
http://www.mail-archive.com/jsmentors@jsmentors.com/

To search via a non-Google archive, visit here: 
http://www.mail-archive.com/jsmentors@googlegroups.com/

To unsubscribe from this group, send email to
jsmentors+unsubscr...@googlegroups.com

Reply via email to