Should we use the $-sign in front of public variables?

I see some people use it. But it seems to serve no purpose. Just a way of naming variables right? Because afaik there is no difference between

_foo = {};$foo = {};$$$$$ = {};foo = {};Aside from the variable having a different name.
http://stackoverflow.com/questions/205853/why-would-a-javascript-variable-start-with-a-dollar-sign

Its likely they kept it to ease the transition from rubies syntax to js. Examples:

Code:
$game_actors # < Ruby global variable for actor data$gameActors // < JS variable for actor data (also globally accessable)
So should scripters use this as well for global variables or omit it?
The only global variable you should ever define is your own module, which is usually written in all uppercase. Everything else you want to be globally available should be a member of this module.
I don't I dont make "public variables" I give you a public class that you can call methods on .. 
Isn't a public class just a public variable in the end?
Isn't a public class just a public variable in the end?
Yes, but you are controlling the way users interact with your class. That's the difference between directly accessing a variable, and accessing it through an interface.


Some people do not like the idea of that extra layer of abstraction due to the performance implications of having to call extra methods, but I believe it is useful.
A class for me is something that can (and usually has to) be instantiated to be used. But sometimes you just need some static functions and don't want to create a new class for it. Therefore i believe it's better to create a namespace (object) and put your class inside of it, together with everything else you want to be accessible.
A class for me is something that can (and usually has to) be instantiated to be used. But sometimes you just need some static functions and don't want to create a new class for it. Therefore i believe it's better to create a namespace (object) and put your class inside of it, together with everything else you want to be accessible.

not if you make the class static. Thats what I do for public API's
So, what's the difference between a static class and a module (namespace). A namespace is just a wrapper for everything under it, like this:

Code:
var NAMESPACE = {};(function() {    // do private stuff.    NAMESPACE.fn = function() {...};    NAMESPACE.cls = myClass;    // ...})();
ES5 code, please, people in this forum want to understand what you write 😉
I dont like the concept of "Name spaces" in ES5 they are hacky and and messy to read. Since you require es5 (even though its more lines of code), the best way to do a static class is:

var something = function() { throw new Error('static class yo') }something.methodForUser = function() { ... }window.something = something;// in game:something.methodForUser();This is five times easier to read, 5 times easier to write and much better then your "name space" concept.

also: http://stackoverflow.com/questions/10054125/why-are-namespaces-considered-bad-practice-in-javascript
I dont like the concept of "Name spaces" in ES5 they are hacky and and messy to read. Since you require es5 (even though its more lines of code), the best way to do a static class is:

var something = function() { throw new Error('static class yo') }something.methodForUser = function() { ... }window.something = something;// in game:something.methodForUser();This is five times easier to read, 5 times easier to write and much better then your "name space" concept.
also: http://stackoverflow.com/questions/10054125/why-are-namespaces-considered-bad-practice-in-javascript
Isn't what you wrote basically the same as what iavra wrote?
So, the differences between those approaches are:

- Object, that can't be instantiated vs function (also object) with an explicit check so it can't be instantiated.

- Explicit "window.<...>" export vs declaration outside of anonymous function.

Regarding the first point, i'm indifferent, as both essentially do the same thing and your approach is a bit more to write.

You export approach has a pro in case of a module/namespace/class used across multiple scripts. While i would do this:

var IAVRA = IAVRA || {};(function() { // ...})();you can do this:
Code:
(function() {    window.IAVRA || (window.IAVRA = {});    //...})();
which has the added benefit of skipping the "IAVRA = IAVRA" in case the object already exists. I actually wanted to do it this way, already, but haven't thought about using the window object itself./edit: Obviously, "= {}" can also be replaced with a function expression.
lets just agree to disagree because it will be a never ending fight 😛

Original thread: https://forums.rpgmakerweb.com/threads/should-we-use-the-sign-in-front-of-public-variables.50853/