Re: Variable data types
- From: Lasse Reichstein Nielsen <lrn@xxxxxxxxxx>
- Date: Sun, 02 Mar 2008 22:17:13 +0100
VK <schools_ring@xxxxxxxxx> writes:
That comes back to the capitalization question and respectively number
vs. Number and boolean vs Boolean. I personally and even if against of
ECMA (who cares! :-) using small letters for primitives and caps for
object wrappers. That helps a lot to avoid confusions like in case
with Mr. Patrick Carey and Co.
As long as one is able to distinguish the primitive type "[Nn]umber"
from the constructor "Number" (one is a concept, the other is a
(function) object), and a primitive number from an object inheriting
from Number.prototype, then I won't care about capitalization. I.e.,
one should always strive to qualify "number" by what it refers to
(type, constructor, (primitive) value or object).
NaN is a value of the Number type.
For the endless fun of mine. Sure, what kind Not-a-Number should else
be :-) ? Maybe another place to spit on ECMA and to say that there are
special values NaN, undefined and null. Just a thought...
Don't blame ECMA for this. NaN is inherited directly from IEEE 754
floating point numbers. It represents the result of a numeric
computation that does not make sense. For a specification that was
supposed to be implemented in hardward, there might not be a way
to fail gracefully. All computations must return a value. NaN is there
for the ones where no other result was appropriate, e.g., Infinity/Infinity.
"internal [[Call]] method" and other ECMA stuff of the kind is a bit
dark as an explanation. Could we tell that functions are objects that
can be used as constructors, so in "var x = new FunctionObject"-like
constructs?
Function are special objects that can also be called as
functions. They are distinguished from non-function objects by
inheriting from Function.prototype and by implementing a hidden
internal method called "[[Call]].
....
It has one singleton Math for math operations (singleton'ess of Math
is broken though on Gecko).
It's just an object. No need to call it a singleton.
I would though: as it is the only one of built-in Javascript objects
that is not allowed to use as a constructor.
The meaning of "singleton" is usually the Singleton (anti-)pattern
from the GOF Patterns book. It is an object oriented way to represent
a type with only one value. Math is just an object. There is no
underlying type that it is the only value of.
From the specification:"5.8 The Math Object
The Math object is a single object that has some named properties,
some of which are functions. "
There are other non-constructor properties of the global object built
into ECMAScript. Math is the only non-function object, though.
The Math object is really only used as a name-space, not as an object
with an identity.
The built-in functions "eval", "parseInt", "parseFloat", "isNaN"
and "isFinite" are functions, and could probably be called as
constructors (with ridiculous results, but without error), but they
aren't really constructors.
try {
var m = new Math;
}
catch (e) {
window.alert(e.message);
// "Object is not a constructor"
}
Yes, this is as the specification says. And just as any other object,
e.g., "var m = new Object();"
An object that gets created by default, exists as a single instance
Single instance of what?
and doesn't allow to create extra instances is a singleton by all
means IMHO?
No. It's just an object. Same as Object.prototype. This one just
happens to be available as a property of the global object (and
Object.prototype just happens to be available as a property of the
Object constructor :).
/L
--
Lasse Reichstein Nielsen - lrn@xxxxxxxxxx
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
.
- References:
- Variable data types
- From: Hal Rosser
- Re: Variable data types
- From: VK
- Re: Variable data types
- From: Lasse Reichstein Nielsen
- Re: Variable data types
- From: VK
- Variable data types
- Prev by Date: Re: Question about arrays
- Next by Date: Re: show number of clicks?
- Previous by thread: Re: Variable data types
- Next by thread: Re: webcrawler (bot) in javascript?
- Index(es):
Relevant Pages
|