As i just said, everything is an object, even a String variable.
I assume what you see above is self explanatory and pretty naive. The entire list of methods and variable for a String object can be found here.
Now, with the basics out of the way, let’s get to some interesting stuff.
So we created a variable person ( i repeat, everything is an object) which hails from the object Object. I am setting properties to it. The method which reads the properties are added to it. Finally the method can be invoked just like any normal method.
I would really suggest using the constructor. In the modern world of numerous frameworks and libraries, the more robust and clean the code, the better.
Having said all that, there is an alternate way for the lazy folks.
In the case above, both a musician and a writer can greet themselves. This is done using the greet method. The method is added to the prototype of both the objects.
The above program would alert the following lines,
Greeting and Salutations from Fyodor
This is the time when Fyodor writes
Greeting and Salutations from Bob
This is the time when Bob sings