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

Can we add var keyword back. thank you! #3121

Closed
lewisou opened this issue Aug 14, 2013 · 4 comments
Closed

Can we add var keyword back. thank you! #3121

lewisou opened this issue Aug 14, 2013 · 4 comments

Comments

@lewisou
Copy link

lewisou commented Aug 14, 2013

Can we add a feature so that i can use 'var' in my function definition to override the globe variable with the same name?

This will be much helpful for our daily life. Can not override globe var is quite danger!

@vendethiel
Copy link
Collaborator

window.$ = -> ...
Also see all the tickets on why our scoping is like that in coffee

@lewisou
Copy link
Author

lewisou commented Aug 14, 2013

By globe scope i mean the file cope.
And when i say globe var i mean an external var that is not created in the local function. which dont need to be an application scope var.

And did you mean i should write:
1 exports.nodeio = require 'node.io'
2 exports.url = require 'url'
3 exports.redis = require 'redis'

4 exports.queue_set = 'queue_set'
5 exports.links_hash = 'links_hash'
...

If not for line 1 - 3, what's the difference between line 3 and line 4. Whey line 4 should be written this way.

And I think when programmer change a variable in a local function, they always mean to write a local var instead of the globe one even there's a globe one with the same name.
if that is true. then i think add a 'globe' key word will be better to bring back the 'var' keyword. That is also what python does.

Now in coffee, the logic weird:
When a programer write n = 'what ever' in a local function: below things happens

  1. when there's a 'n' globe var, then change the globe n.
  2. if there's no globe n, then create a local one, and make an assignment.

The steps are totally opposite to what it should be.

  1. if no globe keywords. then create a local one, and make an assignment. even if there's a globe one with the same name.
  2. if there's an explicit globe leading the expression. then lookup the globe one.

In current coffee implementation. even i don't change a function definition. just adding a globe var can destroy my functions' logic, because the new var's name may conflict with current using local variables.

Please give the ticket link that points to the reason why coffee doing that unusual way. Thank you.

@vendethiel
Copy link
Collaborator

I don't think I really get what you mean. By "globe/global variable", you mean "upperscope variable"? Global variables in node are variables attachee to global.

Please use three backticks (```) for your code

See #2697

@lewisou
Copy link
Author

lewisou commented Aug 14, 2013

By global variable. i mean file scope variable.

see example:

n = 1
function_one = ->
  console.log n

n is a file scope variable. not real global as only functions/classes in the file can access it.
btw, i am using nodejs not browser js. in browser n will be attached to the window object automatically. so we just talked about server side scripts, the nodejs.

I have post an example to ticket #2697 to illustrate what i mean.

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

No branches or pull requests

2 participants