Can I have object with the same name as class in javascript? -
Can I get the object in JavaScript with the same name as the square?
There are no squares in javascript, only methods for creating objects.
To answer your question directly, yes and no. You can create a function that keeps your object, but as soon as you have a variable with the same name, the function is destroyed.
function bob () {// code goes here. Name = "bob"; }
and
var bob = function () {// code goes here. Name = "bob"; }
What if you have declared a variable name like Bob:
var bob = new bob ();
In this case, the function will call Bob, the object will be created, and the function bob will be blocked by the new variable Bob.
If you want to create a singleton, then you can also close it as:
var bob = new (function () { // code here.name = "bob";}) ();
Comments
Post a Comment