You can stick your em-dash up your dot dot dot

So once again I find myself intensely irritated by a growing wave of practice that is touted as correct when its correctness is entirely arbitrary. I’m talking about the finer points of typography. A recent post by Christopher Phin, called T...

Conform your JSON to ECMAScript 4 with JCON Print E-mail
User Rating: / 0
PoorBest 

Oliver Steele is doing great work, and he has just released a gem called JCON which stands for JavaScript Conformance. It tests JSON values to make sure that they are valid for the new world of ECMAScript 4 type definitions (e.g. new { x:int, y:string }( 3, "foo" ) ).

Usage

RUBY:
    type = JCON::parse "[string, int]"
    type.contains?([?a?, 1])     # => true
    type.contains?([?a?, ?b?])   # => false
    type.contains?([?a?, 1, 2])  # => true

    // via RSpec
    [1, ?xyzzy?].should conform_to_js(?[int, string]?)
    [1, 2, ?xyzzy?].should_not conform_to_js(?[int, string]?)  # 2 isn?t a string
    {:x => 1}.should conform_to_js(?{x: int}?)

    // with JavaScript Fu
    # this will succeed if e.g. response contains a script tag that includes
    #   fn("id", {x:1, y:2}, true)
    response.should call_js(?fn?) do |args|
      args[0].should conform_to_js(?string?)
      args[1].should conform_to_js(?{x:int, y:int}?)
      args[2].should conform_to_js(?boolean?)
      # or:
      args.should conform_to_js(?[string, {x:int, y:int}, boolean]?)
    end

In other JSON news, it appears that new ECMAScript standard will no longer reserve the words:

abstract boolean byte char double final float implements int interface
long native package private protected public short static synchronized
throws transient volatile

And Douglas Crockford says that no browsers reserve them, and thus he is unreserving them from jsLint.


Read more at: http://feeds.feedburner.com/~r/ajaxian/~3/272812356/conform-your-json-to-ecmascript-4-with-jcon.
 
< Prev   Next >