Re: Replacing 'new'?
- From: "Dmitry A. Soshnikov" <dmitry.soshnikov@xxxxxxxxx>
- Date: Wed, 23 Sep 2009 06:49:19 -0700 (PDT)
On 23 сен, 15:41, Stefan Weiss <krewech...@xxxxxxxxx> wrote:
On 23/09/09 08:57, Dmitry A. Soshnikov wrote:
the resulting objects could each have
their own copies of methods, instead of referencing common function
objects from a prototype.
Is there any sense in this? Yep, there's one - 'cause objects in ES
are fully mutable, we can make _own_ individual characteristics
(properties/methods) for _some_ objects in constructor (e.g. by
condition - for some objects create additional method, for some - do
not). Any other sense?
Some advantages of this approach are privacy, better encapsulation and
modularity
Ah, that's btw the big (and unfortunately, widespread) mistake - to
use encapsulation only for encapsulation.
Encapsulation in it's main goal is _data abstraction_, but no _data
hiding_. And such "private" and "protected" modifiers provided by some
OOP-realizations - are just and only useful *syntactic sugar* (no
more, mo less) to help _the programmer_ to build more abstract system.
The wrong understanding of encapsulation (such as "the malicious
hacker wants to write data directly into my field, but not via
setter") is the reason of really non-useful and ugly non-abstract
structures when create getter/setter just for simple:
function A() {
var _a; // "private"
this.getA = function _getA() {
return _a;
};
this.setA = function _setA(a) {
_a = a;
};
}
That's really bosh and delirium. There's no any reason do so, calling
such stuff as "privileged" (wth?;) Just, as you correctly mentioned -
increasing of memory usage.
and the ability to refer to the object's properties and
methods without using |this| (inside makeMeASandwich).
is this a good reason to make for 1000 objects 1000 own slots?
P.S.> but, btw, specification has optimization suggestion - joined
objects (13.1.2), when [[Scope]] property is identical of two
functions, realization could use the same function object, but in case
of creating methods in constructor in hardly achieved, 'cause
activation object of constructor can has every call different values,
so [[Scope]] of internal functions will be different.
/ds
.
- Follow-Ups:
- Re: Replacing 'new'?
- From: Stefan Weiss
- Re: Replacing 'new'?
- References:
- Replacing 'new'?
- From: optimistx
- Re: Replacing 'new'?
- From: JR
- Re: Replacing 'new'?
- From: Stefan Weiss
- Re: Replacing 'new'?
- From: Dmitry A. Soshnikov
- Re: Replacing 'new'?
- From: Stefan Weiss
- Replacing 'new'?
- Prev by Date: Re: How to get script query string
- Next by Date: Re: How to get script query string
- Previous by thread: Re: Replacing 'new'?
- Next by thread: Re: Replacing 'new'?
- Index(es):
Relevant Pages
|