Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

experimental commit: derive names for function expressions when we can #131

Closed
wants to merge 1 commit into from

Conversation

michaelficarra
Copy link
Owner

@vendethiel
Copy link
Contributor

So I guess it doesn't harm on IE ? Could be possible to change arguments.callee inside the function body?

@michaelficarra
Copy link
Owner Author

@Nami-Doc: only the non-standard name property, about which I don't care. @satyr actually recommended something like this for CS back in the day, I believe.

@epidemian
Copy link

Looks good to me. It will probably help a lot with debugging; making stack traces more readable :)

It's also good to know that a minifier like UglifyJS can get rid of the unnecessary function name for production code:

$ echo 'foo = -> 99' | bin/coffee --js
// Generated by CoffeeScript 2.0.0-dev
void function () {
  var foo;
  foo = function foo$() {
    return 99;
  };
}.call(this);

$ echo 'foo = -> 99' | bin/coffee --js | uglifyjs --compress --mangle
void function(){var n;n=function(){return 99}}.call(this);

The built-in Redux minifier leaves it as a named function expression though (maybe a missing option to esmangle?):

$ echo 'foo = -> 99' | bin/coffee --js --minify
void function(){foo=function a(){return 99}}.call(this)

Now that i look at it, the minified output also omits the var declaration inside the auto-invoked function, making foo leak into the global scope. Is that an intended behavior or a bug?

@mark-hahn
Copy link

foo = function foo$() {

I thought jeremy vetoed this because it didn't work in IE.

@vendethiel
Copy link
Contributor

He veoted function foo(){}

@mark-hahn
Copy link

I hope I don't have to try to find something in coffeescript issues,
because that is impossible. But I distinctly remember foo = function foo$() { being vetoed. I know for a fact it doesn't work in old IE.

On Sun, Dec 30, 2012 at 4:30 PM, Nami-Doc [email protected] wrote:

He veoted function foo(){}


Reply to this email directly or view it on GitHubhttps://github.com//pull/131#issuecomment-11770659.

@michaelficarra
Copy link
Owner Author

@mark-hahn: The related issues are all linked in the linked FAQ. I'm pretty confident I understand the IE bug. It has been around and well known for quite a while.

var f = function g(){};

behaves like this in IE6:

function g(){}
var f = g;

So the name g is exposed to the containing scope in IE6, not just the function body's scope.

edit: Also, f !== g, so memory use will be higher in IE6. But nothing will break because of the change.

@mark-hahn
Copy link

Sorry. I somehow missed the beginning of this thread.

@michaelficarra
Copy link
Owner Author

@epidemian: I think you've stumbled upon an esmangle bug. I've reported it and it is linked above.

@vendethiel
Copy link
Contributor

@mark-hahn actually, it's fairly easy :p

@michaelficarra
Copy link
Owner Author

I'm going to close this because of general FUD and because I don't want this change affecting the merge into jashkenas/coffee-script.

@devinrhode2
Copy link

Hey Micheal, FWIW I thought of a cleaner way to name object methods:

Module.method = function Module_method() {};

The Module_ prefix is important so you never mistake one function for another

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants