On Mon, May 28, 2012 at 10:50 AM, T.J. Crowder <t...@crowdersoftware.com> wrote:
> On 28 May 2012 18:46, Russell Leggett <russell.legg...@gmail.com> wrote:
>>>
>>> Perhaps this discussion would be aided by a more concrete example.
>
> Doh! Excellent idea. John, if you'd like...? (Otherwise I can do one.)

Here's mine:
Source:
https://github.com/johnjbarton/webdev-examples/tree/gh-pages/Freeze
Site:
http://johnjbarton.github.com/webdev-examples/Freeze/app.html

The application function app() calls the library function
makeExample(), adds a method to it, then calls that method:
function app() {
  var r = makeExample();
  r.discover = function() {
    console.log("I want to call this function");
    return 1;
  };
  r.discover();
}

The result is an error message at the
Uncaught TypeError: Object #<Object> has no method 'discover'.

Note that lib.js is to be written by someone else and overall they do
a great job. They choose 'use strict' and freeze(); that decision is
sound.

I am calling that library. I extend their object in order to fit it
into other libraries I use.

Now imagine that r.discover() is call somewhere else and -- I know
this is hard -- imagine you know nothing about the discussion above.

Maybe my debug skills are not great, but I eventually had to resort to
executing the library code single stepping to figure out why the
method call failed.

I want to just re-iterate that the issue here is not my negative
opinions on the two ingredients, 'use strict' (IMO pointless extra
typing) and 'freeze() (IMO not JS).   The issue here is the modal
object model created from the combination and how to avoid repeating
that mistake.  Without the modal object model, the library writer can
'use strict' and 'freeze()', and I can live with the result or not use
the library. With the modal object model I don't get a choice: I have
to debug the library line by line to discover I can't use it.

jjb

>
> -- T.J.
_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to