R
Ray
Hello,
I'm reading Mr. Flanagan's JS Definitive Guide 5th edition. I was
wondering about a point he make in section 10.2 of the book: "Importing
Symbols from Namespaces".
He mentions in there that one can create an alias for the symbol
defined in a namespace like this:
// This is an easier name, to save typing.
var define = com.davidflanagan.Class.define;
Another way of doing it, again from the same section, is discussed
next:
// Create a simple namespace. No error checking required. The
// module user knows that this symbol does not exist yet.
var Class = {};
// Now import a symbol into this new namespace.
Class.define = com.davidflanagan.Class.define;
Now my question is: what's wrong with aliasing the namespace itself?
E.g.:
var cls = com.davidflanagan.Class;
cls.define();
Why does he need to create a new simple namespace and import the symbol
from one namespace to another? Am I missing something really obvious
here?
Thanks,
Ray
I'm reading Mr. Flanagan's JS Definitive Guide 5th edition. I was
wondering about a point he make in section 10.2 of the book: "Importing
Symbols from Namespaces".
He mentions in there that one can create an alias for the symbol
defined in a namespace like this:
// This is an easier name, to save typing.
var define = com.davidflanagan.Class.define;
Another way of doing it, again from the same section, is discussed
next:
// Create a simple namespace. No error checking required. The
// module user knows that this symbol does not exist yet.
var Class = {};
// Now import a symbol into this new namespace.
Class.define = com.davidflanagan.Class.define;
Now my question is: what's wrong with aliasing the namespace itself?
E.g.:
var cls = com.davidflanagan.Class;
cls.define();
Why does he need to create a new simple namespace and import the symbol
from one namespace to another? Am I missing something really obvious
here?
Thanks,
Ray