JavaScript doesn't have any classes. It only has objects, and objects are like associative arrays in PHP. For example, consider the following PHP code:
$foo = array(
"bar" => "baz",
"baz" => "bar"
);
In JavaScript you would write it as follows:
var foo = {
bar: "baz",
baz: "bar"
};
The really cool thing about JavaScript however is that it has first-class functions. PHP does not (@$&#%! PHP). This means that functions in JavaScript are simply values. You can store them in variables, pass them around as parameters and return values and even put them on objects. For example:
var object = {
add: function (x, y) {
return x + y;
}
};
object.add(2, 3); // 5
Interestingly JavaScript is an amalgamation of both functional and object-oriented programming styles and these two styles of programming are interwoven into the fabric of the language so intricately that it's impossible to separate them.
For example the primary way to create objects in JavaScript is to use functions. A function may be either called normally or be called as a constructor (i.e. by prefixing the function call with the new
keyword). When a function is called as a constructor JavaScript creates a new object behind the scenes and the constructor is used to initialize it. For example:
function Person(firstname, lastname) {
this.fullname = firstname + " " + lastname;
}
var me = new Person("Aadit", "Shah");
alert(me.fullname); // Aadit Shah
In your case the function Server
is a property of the object static
(which effectively makes the function Server
a method of static
). Like methods in other programming languages we call it as follows:
static.Server();
In this case the special variable this
inside the function Server
will point to the object static
because it's called as a method of static
. However this
will not always be static
depending upon the situation:
var o = {};
var Server = static.Server;
Static(); // this will be the global object
Static.call(o); // this will be the object o
new static.Server; // this will be the newly created object
As you can see JavaScript is a very dynamic and versatile language, and it's much more powerful than PHP. I suggest you start learning JavaScript from here: https://developer.mozilla.org/en/learn/javascript