Singleton vs Singleton

  • Thread starter Michael Haufe (\TNO\)
  • Start date
G

Garrett Smith

I take it he wants a Singleton without a constructor property. Did I get
that wrong?
True, the Global Object makes an exception there. There is no description
in the Specification how it is created; it is simply "created before
control enters any execution context" and then it "is there".


Yes, it would. While maybe not accessible from ECMAScript code, host
objects need to have a constructor somewhere by which they have been
constructed.

A host object is not required to have a constructor; not at least as far
as a program is concerned.

I did interpret Asen's meaning of "I want Singleton with properties: -
Doesn't have constructor" to mean that the object would not have a
constructor property.

I can't think of any reason why he would be making program requirements
about unobservable implementation details.

It sounds like you are interpreting the word "constructor" in general
sense, to mean the thing that was new'd, and then further broadening
that to include the implementation details of the Host. That seems to be
broadening context of the discussion.

That is not what I interpreted. I read Asen's message as meaning
"constructor" property, and as something observable by ECMAScript.

An ECMAScript engine's implementation language is not something that the
ECMA-262 gets to decide upon. That language is not required to have
constructors, and so although the implementation most likely does (C,
C++, Java), it is neither required nor observable.
A new'd object automatically gets a [[Prototype]] from the object that
constructed it. The constructor comes from that.

No, the constructor needs to exist before.

My sentence is referring to the `constructor` property. The examples I
posted follow that.

Now if by "constructor" you mean not constructor property, but the
(function) object that implements [[Construct]].

If we are talking about Object, it might be the case that Object is not
present. There is some sort of primordial preservation in
implementations. I am using the term "primordial" to describe what is
built-in, but internally preserved. I got this term from reading
es-discuss subject "Module isolation".

(function(){
Object = null;
return ({}).constructor;
})();

Results null;

The obvious observation, however, is that object *was* created, and so
it may seem odd that the object's constructor property points to global
Object, which is null, yet the the object is created "as if by the
expression `new Object`.

As a bookmarklet:

javascript: alert( function(){Object = null;return ({ ctor :
Object}).ctor;}() )

elerts "null"

The result shows that the object is created. This happens "as if by the
expression `new Object()`". The object literal has a constructor
property that points to Object, which is null (AISB).
The global object's [[Prototype]] is implementation dependent, so it
might have any [[constructor. [...]

I was not talking about the `constructor' property. You miss the point.

Did I? I thought the point was to create a Singleton without a
constructor property. Asen - what was your meaning?
 
A

Asen Bozhilov

Garrett said:
Did I? I thought the point was to create a Singleton without a
constructor property. Asen - what was your meaning?

I mean:

- Doesn't have [[Construct]] method and `Singleton` cannot be use as
part of `new Singleton()` expression.
 
S

Scott Sauyet

Garrett said:
Did I? I thought the point was to create a Singleton without a
constructor property. Asen - what was your meaning?

I mean:

- Doesn't have [[Construct]] method and `Singleton` cannot be use as
part of `new Singleton()` expression.

It's not clear to me, though, if any of the suggestions made in this
thread -- Thomas Lahn's, mine, or your own -- meet your needs. Are
you still looking for a solution to your problem or have you found
one? I know you're not the OP, but it's your criteria that has
generated most of the discussion.

-- Scott
 
T

Thomas 'PointedEars' Lahn

Garrett said:
I take it he wants a Singleton without a constructor property. Did I get
that wrong?

I do not know. He did not write `constructor *property*', so ...
A host object is not required to have a constructor; not at least as far
as a program is concerned.

If by "program" you mean _ECMAScript_ /Program/, then you are right;
otherwise not.
I did interpret Asen's meaning of "I want Singleton with properties: -
Doesn't have constructor" to mean that the object would not have a
constructor property.

Yes, that is one possible interpretation. ISTM that the habit of East
Europeans of omitting articles in English is getting in the way here.
I can't think of any reason why he would be making program requirements
about unobservable implementation details.

The details do not have to be finally unobservable. AISB, objects created
with initializers have a constructor, too. The constructor of {} is (the
Function instance referred to by Object), the constructor of [] is Array,
and the constructor of /./ is RegExp; regardless whether there is a
`constructor' property on the instance or its prototype chain to refer to
it. If he would not be aware of that, this might be the reason for this
rather weird requirement of his (it would be a user-defined object and
AI(SH)SB, every user-defined object has a constructor).
It sounds like you are interpreting the word "constructor" in general
sense, to mean the thing that was new'd, and then further broadening
that to include the implementation details of the Host. That seems to be
broadening context of the discussion.

ISTM this discussion and all your examples are pointless without Asen
saying what he really meant.
That is not what I interpreted. I read Asen's message as meaning
"constructor" property, and as something observable by ECMAScript.

Yes, I got that already. No need of preaching to the choir ;-)
An ECMAScript engine's implementation language is not something that the
ECMA-262 gets to decide upon. That language is not required to have
constructors, and so although the implementation most likely does (C,
C++, Java), it is neither required nor observable.

However, if it is an *object*, it must have a constructor, regardless of
the programming language. That is how OOP works. Even the ECMAScript
Global Object needs to be constructed somehow -- it does not just appear
out of thin air.


PointedEars
 
A

Asen Bozhilov

Thomas said:
Yes, that is one possible interpretation.  ISTM that the habit of East
Europeans of omitting articles in English is getting in the way here.

You are right about my English. I know for people which English is
native, is very hard to reading my posts. Maybe if i read on my native
language - Bulgarian someone, which write like my on English i will be
ignoring. For East Europeans is hard to learn English, because
languages here and English are very different languages. However, i
make every endeavour to learn English and i hope soon my English to be
a better. I will be glad to write here without confusions like this.
Apologize to all members of c.l.js.

ISTM this discussion and all your examples are pointless without Asen
saying what he really meant.

I was write already. I'm not meant `constructor` property, which is
resolve from Prototype chain. I mean internal [[Construct]] method. I
don't want `object' referring from `Singleton` to be used as part of
`new Singleton();` expression. Object literal allow me to do it
that.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,079
Messages
2,570,575
Members
47,207
Latest member
HelenaCani

Latest Threads

Top