Poliquin
Poliquin

Reputation: 2987

Javascript global declaration

I've just started out with javascript and came across this line in a file called global.js There is only one line in the file. I'm not sure what does App do. Any ideas?

Filename: globals.js

//The Application 
App = {};

Upvotes: 0

Views: 66

Answers (5)

jesseniem
jesseniem

Reputation: 177

I would assume that the idea behind the global.js file in your case is to include the file in your base html/template so that the variables in there can be accessed from anywhere in the app.

In some of our projects, we've had global files like this containing references to collections and "setting" variables, which is quite handy :)

Upvotes: 1

everag
everag

Reputation: 7672

This script just instantiate this empty Object. Probably, others scripts that ran along with this uses that object and depends that it is created there.

Upvotes: 0

pete
pete

Reputation: 25091

It (implicitly) declares a variable called App in a "global" context and assigns an empty object as its value. Assuming this is used on a web page somewhere, it's the same as declaring window.App = {}.

How this affects the rest of your application, we won't know until you post more relevant code.

Upvotes: 0

jalynn2
jalynn2

Reputation: 6457

It is creating an object named App in the global namespace. App has no functions or attributes (yet).

Upvotes: 0

T McKeown
T McKeown

Reputation: 12857

it creates an object with a name of App... that's all it does.

Upvotes: 3

Related Questions