Prevent coffeescript from wrapping code into immediately invoked function
NickName:MelkorNemesis Ask DateTime:2013-03-21T23:14:10

Prevent coffeescript from wrapping code into immediately invoked function

I've been going through coffeescript documentation and stackoverflow to find answer for my question to no avail.

I have a javascript file containing just one literal object compiled from coffeescript.

products =
    1:
        name: 'foo'
        id: 1
        description: 'lorem ipsum dolor sit'
        youtube: 'path
    2:
        name: 'bar'
        id: 2
        description: 'lorem ipsum dolor sit'
        youtube: 'path

but what I'm getting back is:

(function() {
    return products = {
      1: {
        name: 'foo lama',
        id: 1,
        ...

I'm loading that file as a resource through ajax and I'm not able to use it as a proper JSON.

Is there a way to prevent coffeescript from wrapping the code into immediately invoked function or (and that'd be the best solution) is there a way to compile only JSON object without naming it?

Thanks

Copyright Notice:Content Author:「MelkorNemesis」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/15551331/prevent-coffeescript-from-wrapping-code-into-immediately-invoked-function

More about “Prevent coffeescript from wrapping code into immediately invoked function” related questions

Prevent coffeescript from wrapping code into immediately invoked function

I've been going through coffeescript documentation and stackoverflow to find answer for my question to no avail. I have a javascript file containing just one literal object compiled from coffeescr...

Show Detail

Immediately invoked functions in CoffeeScript

Could someone show me how to immediately invoke a function in CoffeeScript. I'm trying to accomplish something similar to this JS object literal. WEBAPP = { maxHeight : function(){ /* ...

Show Detail

Immediately invoked named functions

A friend of mine posed an interesting question to me today about how to write immediately invoked named functions in CoffeeScript without hoisting the function variable to the outer scope. In Java...

Show Detail

Prevent Meteor from wrapping scripts in an immediately-invoked function expression

Meteor will wrap an immediately-invoked function expression (IFFE) around the contents of any JS file, to ensure that there are no namespace conflicts between files. I am at the very early stage o...

Show Detail

jQuery immediately invoked function in CoffeeScript?

On the jQuery page explaining how to make plugins, there's this bit of code: (function ( $ ) { var shade = "#556b2f"; $.fn.greenify = function() { this.css( "color", shade ); return t...

Show Detail

Saving a reference to an immediately invoked function

It seems that you're unable to set immediately invoked function expression to a variable: var foo = function() { alert(); }(); // Immediately alerts foo(); // Returns "Uncaught TypeError: foo ...

Show Detail

Coffeescript wrapping files in a function

The coffeescript compiler is, for some reason, wrapping all of my .coffee files in a function when they are compiled. For example, if I have test.coffee: class TestClass constructor: (@value) ...

Show Detail

What are the nuances between the IIFE and the immediately invoked constructor function in JavaScript?

I'm trying to wrap my head around the nuances between the IIFE and the Immediately Invoked Constructor Function in Javascript. From what I can gather from the code below, both functions act like

Show Detail

JavaScript immediately invoked function pattern difference

(function() { console.log('immediately invoked function...'); }.call(this)); (function() { console.log('immediately invoked function...'); }()); &

Show Detail

IIFE (Immediately Invoked Function Expression) in PHP?

I wonder if PHP has any equivalence of IIFE (Immediately Invoked Function Expression) like that of Javascript. Can PHP Closure be written anyhow so it can work similarly to Javascript (invoking,

Show Detail