That condition is very strange, for more than one reason.
It looks like it's trying to see if Map
is supported by the JavaScript engine it's running on (Map
was introduced in ES2015, not all engines have it yet), but the check is flawed and will actually throw an error if the implementation doesn't have Map
. The check should be at least:
var temp = typeof Map != "undefined" && Map.prototype ? new Map() : {} ;
The end result is that you have temp
which might be a plain object, or might be a Map
instance. But you don't use Map
instances and plain objects the same way, so it's strange to do that.
Frankly, I wouldn't worry about that line (and I'd be wary of it and the code around it).
I have gone through many example and tutorials to understand what Map.prototype actually represents.. I have gone through many example and tutorials to understand what Map.prototype actually represents.. in some blogs i saw that it represents Map object but if i have created two Map objects in the same file which one it will refer to?
The object that Map.prototype
refers to is the object that will be used as the prototype of Map
instances. That is:
let m1 = new Map();
let m2 = new Map();
Both of those instances will share the same underlying prototype object, which is the one that Map.prototype
referred to.
That underlying prototype is what gives the instances various features, like the get
and `set methods.
This aspect of your question is covered in more detail in How does JavaScript .prototype work?.