Re: Replacing 'new'?



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

.



Relevant Pages

  • Re: Replacing new?
    ... But encapsulation itself is not related to private and protected: ... The reason is - user needs it. ... errors after that - responsible for that is fully programmer, ...
    (comp.lang.javascript)
  • Re: a method to make js have the ability to inherit
    ... but without the implied type-conversion of the string ... that uses the name of a specific constructor. ... programmer has no idea at all what types of object they are ... no reason for ever doing so. ...
    (comp.lang.javascript)
  • Re: Replacing new?
    ... The reason is - user needs it. ... Here's a good example how encapsulation is made in Python: ... and I agree that concealing one's private parts ... // reduce sandwich size ...
    (comp.lang.javascript)
  • Re: how to use pure c to write OO programs
    ... We can achieve encapsulation - information hiding, data abstraction - in C but not the other two. ... The C computer programming language supports encapsulation but not data hiding. ...
    (comp.lang.c)
  • Re: Structs cannot contain explicit parameterless constructors
    ... I don't know what the real reason is but it may have something ... constructor it would not be called unless you recompiled. ... much influence on the language design. ... IdentityStamp id = obj.Id; ...
    (microsoft.public.dotnet.languages.csharp)