Removing the property of an object within its definition; What for?

Having looked at the recent Google source Maps API downloader , I wonder what the following goal is:

google.maps.Load = function(apiLoad) {
    delete google.maps.Load;
    ...

Why do you need the deleteproperty of an object, inside its definition? I suspect this may lead to some increase in performance, but I cannot understand how a property can remove itself within its definition.

+4
source share
3 answers

This means that the API is loaded only once. However, this will not cause a useful error when the function is called a second time, but may throw an exception.

Here is an alternative solution that causes a more useful error.

google.maps.Load = function() { throw new Error("Already loaded") };
+2

, , .

, Load , .

, V8 ( ) " " ( ).

google.maps.Load = function() {};

google.maps.Load = function() { throw new Error("Already loaded") };

@Sam .

:

+5

, .

+3

All Articles