Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #33259 > unrolled thread

Overriding function and adding a bit

Started byAndrew Poulos <ap_prog@hotmail.com>
First post2017-05-10 11:59 +1000
Last post2017-05-11 09:56 -0700
Articles 20 on this page of 41 — 9 participants

Back to article view | Back to comp.lang.javascript


Contents

  Overriding function and adding a bit Andrew Poulos <ap_prog@hotmail.com> - 2017-05-10 11:59 +1000
    Re: Overriding function and adding a bit Doc O'Leary  <droleary@2017usenet1.subsume.com> - 2017-05-10 15:33 +0000
      Re: Overriding function and adding a bit Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-05-10 19:14 +0200
        Re: Overriding function and adding a bit Doc O'Leary  <droleary@2017usenet1.subsume.com> - 2017-05-10 22:57 +0000
          Re: Overriding function and adding a bit Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-05-11 01:49 +0200
            Re: Overriding function and adding a bit Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-05-11 17:03 +0200
              Re: Overriding function and adding a bit Andrew Poulos <ap_prog@hotmail.com> - 2017-05-12 08:32 +1000
                Re: Overriding function and adding a bit Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-05-12 22:12 +0200
              Re: Overriding function and adding a bit Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-05-12 03:13 +0200
            Re: Overriding function and adding a bit John G Harris <niam@jghnorth.org.uk.invalid> - 2017-05-11 16:33 +0100
              Re: Overriding function and adding a bit Tim Streater <timstreater@greenbee.net> - 2017-05-11 18:54 +0100
            Re: Overriding function and adding a bit Doc O'Leary  <droleary@2017usenet1.subsume.com> - 2017-05-11 22:02 +0000
              Re: Overriding function and adding a bit Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-05-12 01:53 +0200
                Re: Overriding function and adding a bit John G Harris <niam@jghnorth.org.uk.invalid> - 2017-05-12 10:05 +0100
                Re: Overriding function and adding a bit Doc O'Leary  <droleary@2017usenet1.subsume.com> - 2017-05-12 21:43 +0000
                  Re: Overriding function and adding a bit Tim Streater <timstreater@greenbee.net> - 2017-05-12 23:03 +0100
                  Re: Overriding function and adding a bit Julio Di Egidio <julio@diegidio.name> - 2017-05-12 17:28 -0700
                    Re: Overriding function and adding a bit John G Harris <niam@jghnorth.org.uk.invalid> - 2017-05-13 14:39 +0100
                      Re: Overriding function and adding a bit Julio Di Egidio <julio@diegidio.name> - 2017-05-13 07:17 -0700
                        Re: Overriding function and adding a bit Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-05-13 16:25 +0100
                          Re: Overriding function and adding a bit Julio Di Egidio <julio@diegidio.name> - 2017-05-13 08:30 -0700
                            Re: Overriding function and adding a bit Cezary Tomczyk <cezary.tomczyk@gmail.com> - 2017-05-13 17:56 +0200
                              Re: Overriding function and adding a bit Julio Di Egidio <julio@diegidio.name> - 2017-05-13 09:04 -0700
                              Re: Overriding function and adding a bit Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-05-13 20:55 +0100
                                Re: Overriding function and adding a bit Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-05-14 00:00 +0100
                                  Re: Overriding function and adding a bit Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-05-14 03:07 +0100
                                Re: Overriding function and adding a bit Julio Di Egidio <julio@diegidio.name> - 2017-05-13 18:39 -0700
                                  Re: Overriding function and adding a bit John G Harris <niam@jghnorth.org.uk.invalid> - 2017-05-14 11:23 +0100
                                Re: Overriding function and adding a bit John G Harris <niam@jghnorth.org.uk.invalid> - 2017-05-14 11:36 +0100
                                  Re: Overriding function and adding a bit Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-05-14 12:34 +0100
                                    Re: Overriding function and adding a bit Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-05-14 14:11 +0200
                                      Re: Overriding function and adding a bit Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-05-14 15:37 +0100
                                        Re: Overriding function and adding a bit Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-05-14 17:16 +0200
                                    Re: Overriding function and adding a bit Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-05-14 15:40 +0200
            Re: Overriding function and adding a bit Gene Wirchenko <genew@telus.net> - 2017-05-11 15:39 -0700
          Re: Overriding function and adding a bit Tim Streater <timstreater@greenbee.net> - 2017-05-11 10:39 +0100
      Re: Overriding function and adding a bit Julio Di Egidio <julio@diegidio.name> - 2017-05-11 10:05 -0700
    Re: Overriding function and adding a bit Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-05-10 19:13 +0200
      Re: Overriding function and adding a bit Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-05-10 19:22 +0200
      Re: Overriding function and adding a bit Julio Di Egidio <julio@diegidio.name> - 2017-05-11 10:08 -0700
    Re: Overriding function and adding a bit Julio Di Egidio <julio@diegidio.name> - 2017-05-11 09:56 -0700

Page 1 of 3  [1] 2 3  Next page →


#33259 — Overriding function and adding a bit

FromAndrew Poulos <ap_prog@hotmail.com>
Date2017-05-10 11:59 +1000
SubjectOverriding function and adding a bit
Message-ID<RJGdnYVKAvCI6Y_EnZ2dnUU7-SXNnZ2d@westnet.com.au>
I'm working with a tool that generates the HTML etc for an elearning 
course. In The JavaScript that it generates there's this function


function ObjLayerMoveTo(x, y) {
   /* 100+ lines of spaghetti code */
}


This is fine except there are a number of times when the function is 
called on an object when I don't want the function to run.

Basically I want it to be something like


function ObjLayerMoveTo(x, y) {
   if (this.id == "foo") return;

   /* 100+ lines of spaghetti code */
}


To override the existing function and be able to add my code at the top 
I was thinking something like this might work:


var myObjLayerMoveTo = window.ObjLayerMoveTo;

window.ObjLayerMoveTo = function(x, y) {
   if (this.id == "foo") return;
   myObjLayerMoveTo(x, y);
};


Is this the way to approach this?

Andrew Poulos

[toc] | [next] | [standalone]


#33260

FromDoc O'Leary <droleary@2017usenet1.subsume.com>
Date2017-05-10 15:33 +0000
Message-ID<oevbsf$61c$1@dont-email.me>
In reply to#33259
For your reference, records indicate that 
Andrew Poulos <ap_prog@hotmail.com> wrote:

> var myObjLayerMoveTo = window.ObjLayerMoveTo;
> 
> window.ObjLayerMoveTo = function(x, y) {
>    if (this.id == "foo") return;
>    myObjLayerMoveTo(x, y);
> };
> 
> 
> Is this the way to approach this?

Goodness, no.  A major point of OOD is that you can override the 
method in the hierarchy at the appropriate object level.  Define 
an empty ObjLayerMoveTo function on your “foo” object.

-- 
"Also . . . I can kill you with my brain."
River Tam, Trash, Firefly

[toc] | [prev] | [next] | [standalone]


#33262

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2017-05-10 19:14 +0200
Message-ID<5178377.MhkbZ0Pkbq@PointedEars.de>
In reply to#33260
Doc O'Leary wrote:
^^^^^^^^^^^
Get a real name.

> Andrew Poulos <ap_prog@hotmail.com> wrote:
>> var myObjLayerMoveTo = window.ObjLayerMoveTo;
>> 
>> window.ObjLayerMoveTo = function(x, y) {
>>    if (this.id == "foo") return;
>>    myObjLayerMoveTo(x, y);
>> };
>> 
>> 
>> Is this the way to approach this?
> 
> Goodness, no.  A major point of OOD is that you can override the
> method in the hierarchy at the appropriate object level.

Pray tell, what would be the object here?

> Define an empty ObjLayerMoveTo function on your “foo” object.

Who said anything about a “‘foo’ object”?  He wants to *override the 
function*.
 
-- 
PointedEars

Twitter: @PointedEars2
Please do not cc me. / Bitte keine Kopien per E-Mail.

[toc] | [prev] | [next] | [standalone]


#33265

FromDoc O'Leary <droleary@2017usenet1.subsume.com>
Date2017-05-10 22:57 +0000
Message-ID<of05sh$85g$1@dont-email.me>
In reply to#33262
For your reference, records indicate that 
Thomas 'PointedEars' Lahn <PointedEars@web.de> wrote:

> Doc O'Leary wrote:
> ^^^^^^^^^^^
> Get a real name.

Attempt at humor, or trolling from the get-go?

> > Andrew Poulos <ap_prog@hotmail.com> wrote:
> >> var myObjLayerMoveTo = window.ObjLayerMoveTo;
> >> 
> >> window.ObjLayerMoveTo = function(x, y) {
> >>    if (this.id == "foo") return;
> >>    myObjLayerMoveTo(x, y);
> >> };
> >> 
> >> 
> >> Is this the way to approach this?
> > 
> > Goodness, no.  A major point of OOD is that you can override the
> > method in the hierarchy at the appropriate object level.
> 
> Pray tell, what would be the object here?

Whatever the context “this” is referring to such that the id can be 
compared in the first place.

> > Define an empty ObjLayerMoveTo function on your “foo” object.
> 
> Who said anything about a “‘foo’ object”?  He wants to *override the 
> function*.

If you don’t see the use of “foo” in the example code, I cannot help 
you.

-- 
"Also . . . I can kill you with my brain."
River Tam, Trash, Firefly

[toc] | [prev] | [next] | [standalone]


#33266

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2017-05-11 01:49 +0200
Message-ID<20479369.6Emhk5qWAg@PointedEars.de>
In reply to#33265
Doc O'Leary wrote:

> Thomas 'PointedEars' Lahn <PointedEars@web.de> wrote:
>> Doc O'Leary wrote:
>> ^^^^^^^^^^^
>> Get a real name.
> 
> Attempt at humor, or trolling from the get-go?

Are the subscribers of this newsgroup supposed to believe that “Doc O’Leary” 
is your real name?
 
>> > Andrew Poulos <ap_prog@hotmail.com> wrote:
>> >> var myObjLayerMoveTo = window.ObjLayerMoveTo;
>> >> 
>> >> window.ObjLayerMoveTo = function(x, y) {
>> >>    if (this.id == "foo") return;
>> >>    myObjLayerMoveTo(x, y);
>> >> };
>> >> 
>> >> Is this the way to approach this?
>> > Goodness, no.  A major point of OOD is that you can override the
>> > method in the hierarchy at the appropriate object level.
>> Pray tell, what would be the object here?
> 
> Whatever the context “this” is referring to such that the id can be
> compared in the first place.

“this” is not necessarily referring to the same object that the function is 
called as a method of.

The original code of the function is:

  function ObjLayerMoveTo(x, y) {
     /* 100+ lines of spaghetti code */
  }
 
>> > Define an empty ObjLayerMoveTo function on your “foo” object.
>> Who said anything about a “‘foo’ object”?  He wants to *override the
>> function*.
> 
> If you don’t see the use of “foo” in the example code, I cannot help
> you.

"foo" is a primitive string value there.

-- 
PointedEars

Twitter: @PointedEars2
Please do not cc me. / Bitte keine Kopien per E-Mail.

[toc] | [prev] | [next] | [standalone]


#33274

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2017-05-11 17:03 +0200
Message-ID<3160292.R56niFO833@PointedEars.de>
In reply to#33266
Thomas 'PointedEars' Lahn wrote:

> Doc O'Leary wrote:
>> Thomas 'PointedEars' Lahn <PointedEars@web.de> wrote:
>>> > Andrew Poulos <ap_prog@hotmail.com> wrote:
>>> >> var myObjLayerMoveTo = window.ObjLayerMoveTo;
>>> >> 
>>> >> window.ObjLayerMoveTo = function(x, y) {
>>> >>    if (this.id == "foo") return;
>>> >>    myObjLayerMoveTo(x, y);
>>> >> };
>>> >> 
>>> >> Is this the way to approach this?
>>> > Goodness, no.  A major point of OOD is that you can override the
>>> > method in the hierarchy at the appropriate object level.
>>> Pray tell, what would be the object here?
>> 
>> Whatever the context “this” is referring to such that the id can be
            ^^^^^^^^^^^^^^^^^^
>> compared in the first place.
> 
> “this” is not necessarily referring to the same object that the function
> is called as a method of.

Also, the statement above speaks of the common misconception that “this” in 
ECMAScript implementations referred to a(n execution) context.  It does 
_not_.

“this” in a function (execution) context refers to the object of which the 
function is called as a method, or its value is the “undefined” value.

In normal mode, a *direct* function call is equivalent to calling the 
function explicitly as a method of the global object (unless a execution 
context before the global context declares a method of the same name).
That is often *misunderstood* as “this” referring to a(n execution) context 
(instead of an object), because symbols declared in the global context are 
also available as properties of the global object.  In strict mode, however, 
“this” is undefined in that case.

This – and, literally, “this” – can be implicit, using property accessor 
syntax (dot or brackets), for example:

  obj.objLayerMoveTo = ObjLayerMoveTo;

  obj.objLayerMoveTo(42, 23);

  obj["objLayerMoveTo"](42, 23);

This way, “this” inside the called “objLayerMoveTo” *method* would refer to 
the same object as “obj”.

But the required first statement is usually unwise with a host object 
referred to by “obj” as it would attempt to augment that host object or 
override one of its built-in methods.

“this” can also be explicit, using e.g. Function.prototype.call() or 
Function.prototype.apply() (there are other possibilities when used as a 
callback for e.g. Array prototype methods):

  ObjLayerMoveTo.call(obj, 42, 23);

  ObjLayerMoveTo.apply(obj, [42, 23]);

That is safe with a host object referred to by “obj” as it does not augment 
it, but still unwise here because of the global function (it “pollutes the 
global namespace”).

One can surmise from the name of the function and the use of an “id” 
property in the one that is to “override” it, that “this” is supposed to 
refer to an element object, which is a host object.   But while it is 
possible to some extent to modify the prototype of host objects – e.g., 
suppose “obj” would refer to a “div” element object,

  HTMLDivElement.prototype.objLayerMoveTo = function (x, y) {
    /* … */
  };

– it is not compatible, and that modification would not have an effect if 
the host object had been augmented.  Further, modifying the method that the 
host object had been augmented with would compound this former mistake with 
the same one.

However, it should be noted that if something like

  obj.objLayerMoveTo = ObjLayerMoveTo;

or

  obj.onmouseover = ObjLayerMoveTo;

had been executed *before*, then, *without* changing more code, it would be 
necessary to do that anyway.  [The latter assignment would also be _safe_ 
and _not_ a mistake by contrast because the values of those (event-handler) 
properties of element objects are *designed* to be modified that way.]

Because the suggested redefinition of the function would not change the 
reference value that had been assigned to the property of the object 
referred to by “obj”:

             obj
              :
              v
  ,-----------------------.
  | : object[Element]     |
  |-----------------------|       
  | …                     |
  | +… ----------------------.
  | …                     |  :
  `-----------------------'  : (refers to)
                             : 
    ,------------------------'
    :   
    :   ,-----------------------------------.
    `-->| : function[Function]              |
        |-----------------------------------|
        | …                                 |
        | +name : string = "ObjLayerMoveTo" |
        | …                                 |
        `-----------------------------------'
                           ^
                           . calls
                           .
        ,-----------------------------------.
    ,-->| : function[Function]              |
    :   |-----------------------------------|
    :   | …                                 |
    :   | +name : string = "ObjLayerMoveTo" |
    :   | …                                 |
    :   `-----------------------------------'
    :
    `--------------------------.
                               :
  ,-------------------------.  :
  | global : object[Object] |  :
  |-------------------------|  :
  | …                       |  :
  | +ObjLayerMoveTo -----------'
  | …                       |
  `-------------------------'

This is the only way where I think that the *generally* sound idea to 
“override the method in the hierarchy at the appropriate object level”
would hold *some* water in *this* case.

Not so if something like

  ObjLayerMoveTo.call(obj, 42, 23);

or

  ObjLayerMoveTo.apply(obj, [42, 23]);

had been used instead, as “ObjLayerMoveTo” would only be resolved when 
execution reached those lines (closure).
 
-- 
PointedEars

Twitter: @PointedEars2
Please do not cc me. / Bitte keine Kopien per E-Mail.

[toc] | [prev] | [next] | [standalone]


#33286

FromAndrew Poulos <ap_prog@hotmail.com>
Date2017-05-12 08:32 +1000
Message-ID<ZoidnSaGVe_ie4nEnZ2dnUU7-bHNnZ2d@westnet.com.au>
In reply to#33274
On 12/05/2017 1:03 AM, Thomas 'PointedEars' Lahn wrote:
> Thomas 'PointedEars' Lahn wrote:
> 
>> Doc O'Leary wrote:
>>> Thomas 'PointedEars' Lahn <PointedEars@web.de> wrote:
>>>>> Andrew Poulos <ap_prog@hotmail.com> wrote:
>>>>>> var myObjLayerMoveTo = window.ObjLayerMoveTo;
>>>>>>
>>>>>> window.ObjLayerMoveTo = function(x, y) {
>>>>>>     if (this.id == "foo") return;
>>>>>>     myObjLayerMoveTo(x, y);
>>>>>> };
>>>>>>
>>>>>> Is this the way to approach this?
>>>>> Goodness, no.  A major point of OOD is that you can override the
>>>>> method in the hierarchy at the appropriate object level.
>>>> Pray tell, what would be the object here?
>>>
>>> Whatever the context “this” is referring to such that the id can be
>              ^^^^^^^^^^^^^^^^^^
>>> compared in the first place.
>>
>> “this” is not necessarily referring to the same object that the function
>> is called as a method of.
> 
> Also, the statement above speaks of the common misconception that “this” in
> ECMAScript implementations referred to a(n execution) context.  It does
> _not_.
> 
> “this” in a function (execution) context refers to the object of which the
> function is called as a method, or its value is the “undefined” value.
> 
> In normal mode, a *direct* function call is equivalent to calling the
> function explicitly as a method of the global object (unless a execution
> context before the global context declares a method of the same name).
> That is often *misunderstood* as “this” referring to a(n execution) context
> (instead of an object), because symbols declared in the global context are
> also available as properties of the global object.  In strict mode, however,
> “this” is undefined in that case.
> 
> This – and, literally, “this” – can be implicit, using property accessor
> syntax (dot or brackets), for example:
> 
>    obj.objLayerMoveTo = ObjLayerMoveTo;
> 
>    obj.objLayerMoveTo(42, 23);
> 
>    obj["objLayerMoveTo"](42, 23);
> 
> This way, “this” inside the called “objLayerMoveTo” *method* would refer to
> the same object as “obj”.
> 
> But the required first statement is usually unwise with a host object
> referred to by “obj” as it would attempt to augment that host object or
> override one of its built-in methods.
> 
> “this” can also be explicit, using e.g. Function.prototype.call() or
> Function.prototype.apply() (there are other possibilities when used as a
> callback for e.g. Array prototype methods):
> 
>    ObjLayerMoveTo.call(obj, 42, 23);
> 
>    ObjLayerMoveTo.apply(obj, [42, 23]);
> 
> That is safe with a host object referred to by “obj” as it does not augment
> it, but still unwise here because of the global function (it “pollutes the
> global namespace”).
> 
> One can surmise from the name of the function and the use of an “id”
> property in the one that is to “override” it, that “this” is supposed to
> refer to an element object, which is a host object.   But while it is
> possible to some extent to modify the prototype of host objects – e.g.,
> suppose “obj” would refer to a “div” element object,
> 
>    HTMLDivElement.prototype.objLayerMoveTo = function (x, y) {
>      /* … */
>    };
> 
> – it is not compatible, and that modification would not have an effect if
> the host object had been augmented.  Further, modifying the method that the
> host object had been augmented with would compound this former mistake with
> the same one.
> 
> However, it should be noted that if something like
> 
>    obj.objLayerMoveTo = ObjLayerMoveTo;
> 
> or
> 
>    obj.onmouseover = ObjLayerMoveTo;
> 
> had been executed *before*, then, *without* changing more code, it would be
> necessary to do that anyway.  [The latter assignment would also be _safe_
> and _not_ a mistake by contrast because the values of those (event-handler)
> properties of element objects are *designed* to be modified that way.]
> 
> Because the suggested redefinition of the function would not change the
> reference value that had been assigned to the property of the object
> referred to by “obj”:
> 
>               obj
>                :
>                v
>    ,-----------------------.
>    | : object[Element]     |
>    |-----------------------|
>    | …                     |
>    | +… ----------------------.
>    | …                     |  :
>    `-----------------------'  : (refers to)
>                               :
>      ,------------------------'
>      :
>      :   ,-----------------------------------.
>      `-->| : function[Function]              |
>          |-----------------------------------|
>          | …                                 |
>          | +name : string = "ObjLayerMoveTo" |
>          | …                                 |
>          `-----------------------------------'
>                             ^
>                             . calls
>                             .
>          ,-----------------------------------.
>      ,-->| : function[Function]              |
>      :   |-----------------------------------|
>      :   | …                                 |
>      :   | +name : string = "ObjLayerMoveTo" |
>      :   | …                                 |
>      :   `-----------------------------------'
>      :
>      `--------------------------.
>                                 :
>    ,-------------------------.  :
>    | global : object[Object] |  :
>    |-------------------------|  :
>    | …                       |  :
>    | +ObjLayerMoveTo -----------'
>    | …                       |
>    `-------------------------'
> 
> This is the only way where I think that the *generally* sound idea to
> “override the method in the hierarchy at the appropriate object level”
> would hold *some* water in *this* case.
> 
> Not so if something like
> 
>    ObjLayerMoveTo.call(obj, 42, 23);
> 
> or
> 
>    ObjLayerMoveTo.apply(obj, [42, 23]);
> 
> had been used instead, as “ObjLayerMoveTo” would only be resolved when
> execution reached those lines (closure).

Beautiful explanation. Thank you.

Andrew Poulos

[toc] | [prev] | [next] | [standalone]


#33294

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2017-05-12 22:12 +0200
Message-ID<2383552.mvXUDI8C0e@PointedEars.de>
In reply to#33286
Andrew Poulos wrote:

> On 12/05/2017 1:03 AM, Thomas 'PointedEars' Lahn wrote:
>> […]
> 
> Beautiful explanation. Thank you.

You are welcome.

-- 
PointedEars
FAQ: <http://PointedEars.de/faq> | <http://PointedEars.de/es-matrix>
<https://github.com/PointedEars> | <http://PointedEars.de/wsvn/>
Twitter: @PointedEars2 | Please do not cc me./Bitte keine Kopien per E-Mail.

[toc] | [prev] | [next] | [standalone]


#33290

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2017-05-12 03:13 +0200
Message-ID<4301878.31r3eYUQgx@PointedEars.de>
In reply to#33274
Thomas 'PointedEars' Lahn wrote:

>   ,-------------------------.  :
>   | global : object[Object] |  :

This should be

>   | : object[global] |

at least for V8 in Node.js.

However, in Chromium the global object appears to have "Window" as the value 
of its @@toStringTag internal property.

Since ECMAScript 2015, the concept of the @@toStringTag property of an 
object replaces the concept of the internal [[Class]] property for object 
types that are not explicitly recognized by the changed 
Object.prototype.toString() algorithm.

For objects referred by “obj” that have properties and those whose type is 
explictly recognized by the algorithm, obj[Symbol.toStringTag] is the 
“undefined” value.  So obj[Symbol.toStringTag] could provide a more 
efficient to retrieve the equivalent of the former internal [[Class]] 
property than parsing the return value of ({}).toString.call(obj), provided 
that the @@toStringTag property value has not been modified.

However, the Specification explicitly mentions the possibility that programs 
can modify the @@toStringTag property value which makes “legacy type tests” 
unreliable.

Example:

  var o = {
    label: "crook",
    exec: function () {
      /* there’s no there there */
      return null;
    }
  };

  /* I’m not a crook^W^W^W a RegExp, _believe me_[tm]! */
  o[Symbol.toStringTag] = "RegExp";

  /* [object RegExp] */
  ({}).toString.call(o);

Such lies can be thwarted:

  function dontLieToMe (obj)
  {
    var desc = Object.getOwnPropertyDescriptor(o, Symbol.toStringTag);

    return Object.defineProperty(o, Symbol.toStringTag, {
      /* “writable: false, configurable: false” is implicit */
      value: desc ? desc.value : void 0
    });
  }

  var o = {
    label: "crook",
    exec: function () {
      /* there’s no there there */
      return null;
    }
  };

  dontLieToMe(o);

  /* I’m not a crook^W^W^W a RegExp, _believe me_[tm]! */
  o[Symbol.toStringTag] = "RegExp";

  /* [object Object] */
  ({}).toString.call(o);

  /* “Uncaught TypeError: Cannot redefine property:
     Symbol(Symbol.toStringTag)” :-b */
  Object.defineProperty(o, Symbol.toStringTag, {
    value: desc ? desc.value : void 0,
    writable: true
  });

But in the end, duck typing may always be the best approach ;-)
 
<http://www.ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring>
<http://www.ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring>

-- 
PointedEars
FAQ: <http://PointedEars.de/faq> | <http://PointedEars.de/es-matrix>
<https://github.com/PointedEars> | <http://PointedEars.de/wsvn/>
Twitter: @PointedEars2 | Please do not cc me./Bitte keine Kopien per E-Mail.

[toc] | [prev] | [next] | [standalone]


#33275

FromJohn G Harris <niam@jghnorth.org.uk.invalid>
Date2017-05-11 16:33 +0100
Message-ID<tu09hc5qdof2htu3qnlcl91lvk1hrfdrd6@4ax.com>
In reply to#33266
On Thu, 11 May 2017 01:49:35 +0200, Thomas 'PointedEars' Lahn
<PointedEars@web.de> wrote:

>Doc O'Leary wrote:
>
>> Thomas 'PointedEars' Lahn <PointedEars@web.de> wrote:
>>> Doc O'Leary wrote:
>>> ^^^^^^^^^^^
>>> Get a real name.
>> 
>> Attempt at humor, or trolling from the get-go?
>
>Are the subscribers of this newsgroup supposed to believe that “Doc O’Leary” 
>is your real name?
  <snip>

Since when has anyone "subscribed" to a news group ?

Will Thomas ever tell us what a "real" name is ? 

Are Thomas 'PointedEars' Lahn, Elizabeth R, Mark Twain, and George
Orwell "real" names ?

Remember what Thomas Lahn said
> But this is a technical newsgroup; we must aspire here to be
> *correct* and *precise* instead of catering to the misconceptions 
> and ambiguity of the general public.

  John

[toc] | [prev] | [next] | [standalone]


#33281

FromTim Streater <timstreater@greenbee.net>
Date2017-05-11 18:54 +0100
Message-ID<110520171854388321%timstreater@greenbee.net>
In reply to#33275
In article <tu09hc5qdof2htu3qnlcl91lvk1hrfdrd6@4ax.com>, John G Harris
<niam@jghnorth.org.uk.invalid> wrote:

>On Thu, 11 May 2017 01:49:35 +0200, Thomas 'PointedEars' Lahn
><PointedEars@web.de> wrote:
>
>>Doc O'Leary wrote:
>>
>>> Thomas 'PointedEars' Lahn <PointedEars@web.de> wrote:
>>>> Doc O'Leary wrote:
>>>> ^^^^^^^^^^^
>>>> Get a real name.
>>> 
>>> Attempt at humor, or trolling from the get-go?
>>
>>Are the subscribers of this newsgroup supposed to believe that „Doc O‚Leary‰ 
>>is your real name?
>  <snip>
>
>Since when has anyone "subscribed" to a news group ?
>
>Will Thomas ever tell us what a "real" name is ? 
>
>Are Thomas 'PointedEars' Lahn, Elizabeth R, Mark Twain, and George
>Orwell "real" names ?
>
>Remember what Thomas Lahn said
>> But this is a technical newsgroup; we must aspire here to be
>> *correct* and *precise* instead of catering to the misconceptions 
>> and ambiguity of the general public.

Perhaps PointyHad should ask the White Knight.

-- 
"That excessive bail ought not to be required, nor excessive fines imposed,
nor cruel and unusual punishments inflicted"  --  Bill of Rights 1689

[toc] | [prev] | [next] | [standalone]


#33285

FromDoc O'Leary <droleary@2017usenet1.subsume.com>
Date2017-05-11 22:02 +0000
Message-ID<of2n22$f1d$1@dont-email.me>
In reply to#33266
For your reference, records indicate that 
Thomas 'PointedEars' Lahn <PointedEars@web.de> wrote:

> Are the subscribers of this newsgroup supposed to believe that “Doc O’Leary” 
> is your real name?

I don’t have a “real” name.  They’ve all been made up, including the one 
that was put on my birth certificate.  I’ve been using Doc O’Leary on 
Usenet since at least 1990:

<https://groups.google.com/forum/?hl=en#!msg/comp.sys.mac.games/-IovAUnRamE/PVW8_4orEo8J>

How about yourself, Pointy?  Though I really don’t see how any of this 
matters to the topic at hand.  Focus.

> “this” is not necessarily referring to the same object that the function is 
> called as a method of.

Well, it has to be referring to *something* for the code to work as 
expected.  I see no reason *not* to call it as a method on the target 
object (or prototype thereof), thus allowing the OP to override the 
special case of the “foo” object that needs to behave differently.

> The original code of the function is:
> 
>   function ObjLayerMoveTo(x, y) {
>      /* 100+ lines of spaghetti code */
>   }

Which says nothing about how it is called, or the larger context in 
which it was defined.  The issue at hand remains what “this” is 
actually referring to.  Focus.

> "foo" is a primitive string value there.

Used with a particular intent.  My suggestion stands.

-- 
"Also . . . I can kill you with my brain."
River Tam, Trash, Firefly

[toc] | [prev] | [next] | [standalone]


#33288

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2017-05-12 01:53 +0200
Message-ID<10849548.O9o76ZdvQC@PointedEars.de>
In reply to#33285
Doc O'Leary wrote:

> For your reference, records indicate that
> Thomas 'PointedEars' Lahn <PointedEars@web.de> wrote:

It is called attribution _line_, not attribution novel.

>> Are the subscribers of this newsgroup supposed to believe that “Doc
>> O’Leary” is your real name?
>
> I don’t have a “real” name.

Thanks for the clarification.  Score adjusted.

> They’ve all been made up, including the one that was put on my birth
> certificate.

The name on whatever current official document of identity you have is your 
real name.  Look it up.  (But, of course, you already know that.)

> I’ve been using Doc O’Leary on Usenet since at least 1990:

Your problem.
 
> […]
> How about yourself, Pointy?  Though I really don’t see how any of this
> matters to the topic at hand.  Focus.

As you can read everywhere, my real name is Thomas Lahn.  As customary in 
Usenet, I have inserted my nickname between my first name and last name in 
the “From” header field value – the former is “PointedEars”, _not_ “Pointy”.  
But, of course, as you have been using Usenet “since at least 1990”, you 
know all of that.  You are just trolling – typical for a pseudonymous 
wannabe.
 
>> “this” is not necessarily referring to the same object that the function
>> is called as a method of.
> 
> Well, it has to be referring to *something* for the code to work as
> expected.  I see no reason *not* to call it as a method on the target
> object (or prototype thereof), thus allowing the OP to override the
> special case of the “foo” object that needs to behave differently.

My point is that “this” can be anything (except an execution context, 
contrary to what you thought), and the comparison would work with
anything except a value for “this” that cannot be converted to an object.
 
>> The original code of the function is:
>> 
>>   function ObjLayerMoveTo(x, y) {
>>      /* 100+ lines of spaghetti code */
>>   }
> 
> Which says nothing about how it is called, or the larger context in
> which it was defined.

Exactly.  So it is a jump to conclusions on your part that it would be 
inappropriate to simply redefine the function as the OP suggested.  You
have not even come up with a convincing argument for a case where this
would not work as intended (you left that part to me).

EOD

-- 
PointedEars
FAQ: <http://PointedEars.de/faq> | <http://PointedEars.de/es-matrix>
<https://github.com/PointedEars> | <http://PointedEars.de/wsvn/>
Twitter: @PointedEars2 | Please do not cc me./Bitte keine Kopien per E-Mail.

[toc] | [prev] | [next] | [standalone]


#33292

FromJohn G Harris <niam@jghnorth.org.uk.invalid>
Date2017-05-12 10:05 +0100
Message-ID<oluahc92e3k6e3nkd00sbktcg8n8dbsp0c@4ax.com>
In reply to#33288
On Fri, 12 May 2017 01:53:30 +0200, Thomas 'PointedEars' Lahn
<PointedEars@web.de> wrote:

  <snip>
>The name on whatever current official document of identity you have is your 
>real name.  Look it up.  (But, of course, you already know that.)
  <snip>

What nonsense. If you look up "real name" in the Oxford Dictionary of
English or the Oxford Dictionary of Law you won't find it. What you
will find if you look up "the" in the Oxford Dictionary of English is
that "the O'Donoghue" is a perfectly valid name in the United Kingdom
and Ireland.

As for "official document of identity", some people don't have one. At
least a few years ago French people who gave their children Breton
names were not allowed to have a birth certificate.

Finally, it takes about one minute to find Doc O'Leary's current
employment name, if anyone is in the least bit interested.

  John

[toc] | [prev] | [next] | [standalone]


#33295

FromDoc O'Leary <droleary@2017usenet1.subsume.com>
Date2017-05-12 21:43 +0000
Message-ID<of5a9t$eko$1@dont-email.me>
In reply to#33288
For your reference, records indicate that 
Thomas 'PointedEars' Lahn <PointedEars@web.de> wrote:

> Doc O'Leary wrote:
> 
> > For your reference, records indicate that
> > Thomas 'PointedEars' Lahn <PointedEars@web.de> wrote:
> 
> It is called attribution _line_, not attribution novel.

Oh, boo hoo again.  Please consult with a mental health professional 
if these sorts of things are really causing you distress.

> > I’ve been using Doc O’Leary on Usenet since at least 1990:
> 
> Your problem.

Hasn’t been.  It really seems like you’re the only one who has 
trouble with variable names.  Get it?  Ha-Haaaaa!

> > How about yourself, Pointy?  Though I really don’t see how any of this
> > matters to the topic at hand.  Focus.
> 
> As you can read everywhere, my real name is Thomas Lahn.

Nobody would care one way or the other if it wasn’t.  This is all 
entirely off topic anyway, which gets back to your inability to 
focus on what’s really important.  Again, seek professional help 
on that.

> You
> have not even come up with a convincing argument for a case where this
> would not work as intended (you left that part to me).

It is pointless to make any argument in either direction.  It is 
simply incumbent on the OP to either clarify his code so that he 
can be given a more specific answer, or to take my suggestion to 
just use polymorphism, which exists precisely to address this sort 
of need.  Everything else is idle speculation.

-- 
"Also . . . I can kill you with my brain."
River Tam, Trash, Firefly

[toc] | [prev] | [next] | [standalone]


#33296

FromTim Streater <timstreater@greenbee.net>
Date2017-05-12 23:03 +0100
Message-ID<120520172303192383%timstreater@greenbee.net>
In reply to#33295
In article <of5a9t$eko$1@dont-email.me>, Doc O'Leary
<droleary@2017usenet1.subsume.com> wrote:

>For your reference, records indicate that 
>Thomas 'PointedEars' Lahn <PointedEars@web.de> wrote:
>
>> Doc O'Leary wrote:
>> 
>> > For your reference, records indicate that
>> > Thomas 'PointedEars' Lahn <PointedEars@web.de> wrote:
>> 
>> It is called attribution _line_, not attribution novel.
>
>Oh, boo hoo again.  Please consult with a mental health professional 
>if these sorts of things are really causing you distress.

It's another of his stock lines.

Keep it coming, Doc. I'm just gonna sit back and enjoy PointyHead
getting a well-deserved spanking.

-- 
"Once you adopt the unix paradigm, the variants cease to be a problem - you
bitch, of course, but that's because bitching is fun, unlike M$ OS's, where 
bitching is required to keep your head from exploding." - S Stremler in afc

[toc] | [prev] | [next] | [standalone]


#33297

FromJulio Di Egidio <julio@diegidio.name>
Date2017-05-12 17:28 -0700
Message-ID<05f57f29-8dd8-4829-9952-7ffd20411fb5@googlegroups.com>
In reply to#33295
On Friday, May 12, 2017 at 11:46:50 PM UTC+2, Doc O'Leary wrote:
<snip>
> It is 
> simply incumbent on the OP to either clarify his code so that he 
> can be given a more specific answer, or to take my suggestion to 
> just use polymorphism, which exists precisely to address this sort 
> of need.  Everything else is idle speculation.

Your "this sort of need" is the idle speculation here: indeed your
suggestion remains just wrong, i.e. regardless of the OP.  I'll say it
more explicitly: to suggest OO patterns to architect JS code is simple
an utter mistake, that you propose so or that some vendors now are
proposing so...

That said, please do get a real name and email address: it is basic Usenet
etiquette, indeed since the old days.

*Plonk*

Julio

[toc] | [prev] | [next] | [standalone]


#33299

FromJohn G Harris <niam@jghnorth.org.uk.invalid>
Date2017-05-13 14:39 +0100
Message-ID<i33ehchjsvk1mkaja9tnf1njj5g2nncqv4@4ax.com>
In reply to#33297
On Fri, 12 May 2017 17:28:02 -0700 (PDT), Julio Di Egidio
<julio@diegidio.name> wrote:

>On Friday, May 12, 2017 at 11:46:50 PM UTC+2, Doc O'Leary wrote:
><snip>
  <snip>

>to suggest OO patterns to architect JS code is simple
>an utter mistake, that you propose so or that some vendors now are
>proposing so...

Are you saying ECMAScript programs can't or shouldn't implement an OO
design? If so, how do you justify your belief?


>That said, please do get a real name and email address: it is basic Usenet
>etiquette, indeed since the old days.

Anyone who knows a little about the internet can demonstrate that his
e-mail address is real and then find his other name within seconds.


>*Plonk*

Why bother telling us?

  John

[toc] | [prev] | [next] | [standalone]


#33300

FromJulio Di Egidio <julio@diegidio.name>
Date2017-05-13 07:17 -0700
Message-ID<f929791c-3e67-40af-a56e-d79722abd193@googlegroups.com>
In reply to#33299
On Saturday, May 13, 2017 at 3:39:44 PM UTC+2, John G Harris wrote:
> On Fri, 12 May 2017 17:28:02 -0700 (PDT), Julio Di Egidio
> <julio@diegidio.name> wrote:
> 
> >to suggest OO patterns to architect JS code is simple
> >an utter mistake, that you propose so or that some vendors now are
> >proposing so...
> 
> Are you saying ECMAScript programs can't or shouldn't implement an OO
> design? If so, how do you justify your belief?

You may have beliefs, I am a software professional and that (what I said,
not how you rephrase it) is just the A in the ABC of JavaScript.  That said,
I might explain more (to those who want to learn), not only about JS vs OO,
but also about where all that utter and utterly destructive bullshit comes
from, but you'll have to learn to ask questions honestly and politely first,
and show some respect for the discipline and then the profession, as you
would with your doctor or even just with the plumber (unless you are a
plumber).

Julio

[toc] | [prev] | [next] | [standalone]


#33301

FromBen Bacarisse <ben.usenet@bsb.me.uk>
Date2017-05-13 16:25 +0100
Message-ID<877f1kg4mz.fsf@bsb.me.uk>
In reply to#33300
Julio Di Egidio <julio@diegidio.name> writes:

> On Saturday, May 13, 2017 at 3:39:44 PM UTC+2, John G Harris wrote:
>> On Fri, 12 May 2017 17:28:02 -0700 (PDT), Julio Di Egidio
>> <julio@diegidio.name> wrote:
>> 
>> >to suggest OO patterns to architect JS code is simple
>> >an utter mistake, that you propose so or that some vendors now are
>> >proposing so...
>> 
>> Are you saying ECMAScript programs can't or shouldn't implement an OO
>> design? If so, how do you justify your belief?
>
> You may have beliefs, I am a software professional and that (what I said,
> not how you rephrase it) is just the A in the ABC of JavaScript.

ECMAScript uses prototype-based inheritance rather than class-based
inheritance but that does not mean it is not and object-oriented
language not that one should not write object-oriented programs using
it.

From page 1 of ECMA 262 (6th edition):

  "ECMAScript is an object-oriented programming language..."

Obviously you can't use the same design techniques as you would do with
class-based object languages, but that's not quite the same point.

<snip>
-- 
Ben.

[toc] | [prev] | [next] | [standalone]


Page 1 of 3  [1] 2 3  Next page →

Back to top | Article view | comp.lang.javascript


csiph-web