Documentation? Running curl from the browser console. #74

Closed
SimplGy opened this Issue Mar 21, 2012 · 4 comments

Comments

Projects
None yet
2 participants

SimplGy commented Mar 21, 2012

I think this is not allowed, but it would be great to know that for sure and be able to read a brief explanation of why. Is the console not allowed to add scripts? Does curl not have the same access to executing code in the console?

define([
    'components/lightbox'
],function(lightbox){
    lightbox('hello');
});

This works in an included JS module, but not from the console. Am I doing something wrong trying to run this in Chrome or Firefox's console?

Owner

unscriptable commented Mar 21, 2012

Hey @simpleascouldbe!

I see two minor issues with your code snippet.

  1. Anonymous modules only work if the loader can figure out the module id from the file name. Just add a module id and it'll work.

  2. The call to lightbox will execute immediately upon module definition. If you want a module that you can call repeatedly, you should have it return a function:

    define('myModule', ['components/lightbox'],function (lightbox){
    return function () {
    lightbox('hello');
    };
    });

Try that. :)

-- John

@ghost ghost assigned unscriptable Mar 21, 2012

Owner

unscriptable commented Mar 21, 2012

You are right. This needs to be documented. :)

SimplGy commented Mar 22, 2012

I was mixed up. I'm doing a single-page app that only bootstraps in once.

I got so used to starting views with a 'define' that I forgot the application actually used 'curl' to kick everything off.

This works just fine against an already-defined curl module:

curl(['components/lightbox'], function(lightbox){
    lightbox('hello');
});

I added a page to the wiki (couldn't figure out how to put it in the right category though). Hope it helps, feel free to edit or delete if it's not what you're looking for.

https://github.com/cujojs/curl/wiki/Using-curl.js-from-a-browser-console

@SimplGy SimplGy closed this Mar 22, 2012

Owner

unscriptable commented Mar 22, 2012

Wow, thanks Eric! I'm going to add some very minor adjustments and put it on the main page! -- J

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment