LearnBoost/stylus — Issue #526: Feature suggestion: Ability to scope variables to files
Author: ianstormtaylor
Created: 2012-01-18 03:19:17+00:00
State: open

Sorry that I'm going crazy on Stylus recently, just thinking of things as I'm writing in it. It would be nice if variables were able to be contained to the file they were defined in

```
this = 'local'
global that = 'global'
```

I don't exactly know what syntax you'd want for it, the trick is that people have already started using stylus and top-level vars are globals, so maybe it needs to be switched:

```
local this = 'local'
that = 'global'
```

A use case I see this being useful for:

```
_border-vertical = border-vertical() if border-vertical is a 'function' // keeps a reference to an existing function
border-vertical()
...
```

Here i want to keep a reference to call at the end of the function, but that assignment has to be at the top-level of the file. With scoped variables the global space doesn't need to have a `_border-vertical()` in it unnecessarily just because I imported a helper.

And then I was also thinking, could it also be useful to create global variables from inside functions? because right now they're local only if I'm not mistaken. (This would be necessary to have functions that build other functions)

Hopefully that makes sense... thinking outloud.