So for those who have been dealing with Object Oriented Programming languages, such as ActionScript 3.0, Java, Python etc. working with a scripting language can be a little effort intense. OOP languages offers us a lot of flexibility and frankly, software development flexibility, is something that started to turn into a need rather than a convenience in the last period.
These are some theoretical aspects of the language when it is used to 'simulate' object orientation.
Types are associated with values rather than variables. It means that a variable bound to a number can be bound to a string later on.
And it's totally fine.
var x = 5;
var x = "five"; // WTF?
Functions are Objects:
For that, they have properties and methods. They can be assigned to variables, returned by other functions, passed to arguments and so on.
Prototypes are used instead of classes and inheritance. Many class-based features can be simulated with the use of
Functions can be Object Constructors:
Invoking a function with the
new keyword, creates a new object and calls that function with its local
this keyword bound to that object for that invocation:
var dude = new Dude();
dude.name = "bob";
nameproperty is bound to the
dudeobject and not to the global scope.
Functions can also be methods:
this keyword is bound to that object for that invocation.
These are the points to keep in mind so far. Stay tuned for the next post, where I'll be covering further practical examples, such as writing classes, public/private/static methods, class properties and so on.