How to modify the scope chain without `with` ?

Garrett Smith dhtmlkitchen at
Tue Feb 16 17:38:47 UTC 2016

On Mon, Feb 15, 2016 at 1:13 AM, Coroutines <coroutines at> wrote:

> This post might be overly wordy.  Sorry.  It relates to the
> functionality provided by the `with` keyword and why I think it's
> important in the future.
> I am currently rewriting a templating module that I think is very
> useful for it's ability to turn a function in coffeescript syntax into
> a sort of DSL - something that looks like this:
> template = ->
>   doctype 5
>   html ->
>     head ->
>       title @title
>     body ->
>       div id: 'content', ->
>         if @posts?
>           for p in @posts
>             div class: 'post', ->
>               p
>               div p.comment
>       form method: 'post', ->
>         ul ->
>           li -> input name: 'name'
>           li -> textarea name: 'comment'
>           li -> input type: 'submit'
> For those not familiar with Coffeescript, "= ->" creates a function
> with no arguments, the indented sub-block is the body of the function.
> All of these things essentially compile into nested functions like:
> html(head(title(this.title))
> (not an exact translation)
> Anyway, this library/module called (ck) exploits the little-used
> `with` keyword.  It creates a function like this:
> function (scope, template) { with (scope) { template(); } }
> So the template is just a series of functions that lookup within
> `scope` for a function creating HTML.  The problem is this module
> (imo) wastefully creates a lot of closures to create the HTML tags.

I think you'll have a lot better luck starting out like I did: Learn
HTML first. You're working on some complicated stuff there, and for
me, I always try to get simple to work. Simple and working is good!

You cannot have too solid of a grasp of HTML. Ditto for CSS.

When it comes to javascript, context and scope can be tricky and
confusing for those coming from other languages.

Thank you,

More information about the es-discuss mailing list