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


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

the definition of this

Started byruben safir <ruben@mrbrklyn.com>
First post2018-07-07 20:59 -0400
Last post2018-07-08 13:44 -0700
Articles 16 — 7 participants

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


Contents

  the definition of this ruben safir <ruben@mrbrklyn.com> - 2018-07-07 20:59 -0400
    Re: the definition of this ruben safir <ruben@mrbrklyn.com> - 2018-07-07 21:02 -0400
      Re: the definition of this Robert Heller <heller@deepsoft.com> - 2018-07-07 21:15 -0500
      Re: the definition of this JJ <jj4public@vfemail.net> - 2018-07-08 10:17 +0700
    Re: the definition of this Julio Di Egidio <julio@diegidio.name> - 2018-07-08 04:49 -0700
    Re: the definition of this ruben safir <ruben@mrbrklyn.com> - 2018-07-08 12:17 -0400
      Re: the definition of this Julio Di Egidio <julio@diegidio.name> - 2018-07-08 10:43 -0700
      Re: the definition of this Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2018-07-08 22:49 +0200
        Re: the definition of this Julio Di Egidio <julio@diegidio.name> - 2018-07-08 13:55 -0700
    Re: the definition of this Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2018-07-08 21:51 +0200
      Re: the definition of this Julio Di Egidio <julio@diegidio.name> - 2018-07-08 13:00 -0700
        Re: the definition of this Julio Di Egidio <julio@diegidio.name> - 2018-07-08 13:04 -0700
          Re: the definition of this "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2018-07-08 13:48 -0700
            Re: the definition of this Julio Di Egidio <julio@diegidio.name> - 2018-07-08 13:51 -0700
        Re: the definition of this "Christoph M. Becker" <cmbecker69@arcor.de> - 2018-07-08 22:26 +0200
          Re: the definition of this Julio Di Egidio <julio@diegidio.name> - 2018-07-08 13:44 -0700

#35372 — the definition of this

Fromruben safir <ruben@mrbrklyn.com>
Date2018-07-07 20:59 -0400
Subjectthe definition of this
Message-ID<phrnlo$34c$1@reader1.panix.com>
I was reviewing this simple program from the w3schools tutorials and it
confused me.  A short version of it looks like this:

 77     transition: 0.3s;
 78 }
 79
 80 .close:hover,
 81 .close:focus {
 82     color: #bbb;
 83     text-decoration: none;
 84     cursor: pointer;
 85 }
 86
 87 /* 100% Image Width on Smaller Screens */
 88 @media only screen and (max-width: 700px){
 89     .modal-content {
 90         width: 100%;
 91     }
 92 }
 93 </style>
 94 </head>
 95 <body>
 96
 97 <h2>Image Modal</h2>
 98 <p>In this example, we use CSS to create a modal (dialog box) that
is hidden by default.</p>
 99 <p>We use JavaScript to trigger the modal and to display the current
image inside the modal when it is clicked on. Also note that we use the
value from the image's "alt" attr    ibute as an image caption text
inside the modal.</p>
100
101 <img id="myImg"
src="http://www.mrbrklyn.com/images/comics/action_78.jpg" alt="Action
Comics" style="width:100%;max-width:300px">
102
103 <!-- The Modal -->
104 <div id="myModal" class="modal">
105   <span class="close">&times;</span>
106   <img class="modal-content" id="img01">
107   <div id="caption"></div>
108 </div>
109
110 <script>
111 // Get the modal
112 var modal = document.getElementById('myModal');
113
114 // Get the image and insert it inside the modal - use its "alt" text
as a caption
115 var lc_img = document.getElementById('myImg');
116 var mo = document.getElementById("img01");
117 var captionText = document.getElementById("caption");
118 lc_img.onclick = function(){
119    ¦modal.style.display = "block";
120    ¦mo.src = this.src;
121    ¦captionText.innerHTML = this.alt;
122 }
123
124 // Get the <span> element that closes the modal
125 var span = document.getElementsByClassName("close")[0];
126
127 // When the user clicks on <span> (x), close the modal
128 span.onclick = function() {
129    ¦modal.style.display = "none";
130 }
131 </script>
132
133 </body>
134 </html>


So line 120 assigns the url for the clicked upon image into the mo.src
variable and turns it on.  But I would have thought that this would be a
reference to the document object, not the image that was clicked, so
obviously I am confused about the rules of object heiarchy.  Otherwise,
how is var mo visible within the function?

[toc] | [next] | [standalone]


#35373

Fromruben safir <ruben@mrbrklyn.com>
Date2018-07-07 21:02 -0400
Message-ID<phrnr8$34c$2@reader1.panix.com>
In reply to#35372
Sorry, the code looks line this

  1 <!DOCTYPE html>
  2 <html>
  3 <head>
  4 <meta name="viewport" content="width=device-width, initial-scale=1">
  5 <style>
  6 body {font-family: Arial, Helvetica, sans-serif;}
  7 
  8 #myImg {
  9     border-radius: 5px;
 10     cursor: pointer;
 11     transition: 0.3s;
 12 }
 13 
 14 #myImg:hover {opacity: 0.7;}
 15 
 16 /* The Modal (background) */
 17 .modal {
 18     display: none; /* Hidden by default */
 19     position: fixed; /* Stay in place */
 20     z-index: 1; /* Sit on top */
 21     padding-top: 100px; /* Location of the box */
 22     left: 0;
 23     top: 0;
 24     width: 100%; /* Full width */
 25     height: 100%; /* Full height */
 26     overflow: auto; /* Enable scroll if needed */
 27     background-color: rgb(0,0,0); /* Fallback color */
 28     background-color: rgba(0,0,0,0.7); /* Black w/ opacity */
 29 }
 30 
 31 /* Modal Content (image) */
 32 .modal-content {
 33     margin: auto;
 34     display: block;
 35     width: 100%;
 36     max-width: 700px;
 37 }
 38 
 39 /* Caption of Modal Image */
 40 #caption {
 41     margin: auto;
 42     display: block;
 43     width: 80%;
 44     max-width: 700px;
 45     text-align: center;
 46     color: #ccc;
 47     padding: 5px 0;
 48     height: 150px;
 49 }
 50 
 51 /* Add Animation */
 52 .modal-content, #caption {
 53     -webkit-animation-name: zoom;
 54     -webkit-animation-duration: 0.6s;
 55     animation-name: zoom;
 56     animation-duration: 0.6s;
 57 }
 58 
 59 @-webkit-keyframes zoom {
 60     from {-webkit-transform:scale(0)}
 61     to {-webkit-transform:scale(1)}
 62 }
 63 
 64 @keyframes zoom {
 65     from {transform:scale(0)}
 66     to {transform:scale(1)}
 67 }
 68 
 69 /* The Close Button */
 70 .close {
 71     position: absolute;
 72     top: 15px;
 73     right: 35px;
 74     color: #f1f1f1;
 75     font-size: 40px;
 76     font-weight: bold;
 77     transition: 0.3s;
 78 }
 79 
 80 .close:hover,
 81 .close:focus {
 82     color: #bbb;
 83     text-decoration: none;
 84     cursor: pointer;
 85 }
 86 
 87 /* 100% Image Width on Smaller Screens */
 88 @media only screen and (max-width: 700px){
 89     .modal-content {
 90         width: 100%;
 91     }
 92 }
 93 </style>
 94 </head>
 95 <body>
 96 
 97 <h2>Image Modal</h2>
 98 <p>In this example, we use CSS to create a modal (dialog box) that is hidden by default.</p>
 99 <p>We use JavaScript to trigger the modal and to display the current image inside the modal when it is clicked on. Also note that we use the value from the image's "alt" attr    ibute as an image caption text inside the modal.</p>
100 
101 <img id="myImg" src="http://www.mrbrklyn.com/images/comics/action_78.jpg" alt="Action Comics" style="width:100%;max-width:300px">
102 
103 <!-- The Modal -->
104 <div id="myModal" class="modal">
105   <span class="close">&times;</span>
106   <img class="modal-content" id="img01">
107   <div id="caption"></div>
108 </div>
109 
110 <script>
111 // Get the modal
112 var modal = document.getElementById('myModal');
113 
114 // Get the image and insert it inside the modal - use its "alt" text as a caption
115 var lc_img = document.getElementById('myImg');
116 var mo = document.getElementById("img01");
117 var captionText = document.getElementById("caption");
118 lc_img.onclick = function(){
119    ¦modal.style.display = "block";
120    ¦mo.src = this.src;
121    ¦captionText.innerHTML = this.alt;
122 }
123 
124 // Get the <span> element that closes the modal
125 var span = document.getElementsByClassName("close")[0];
126 
127 // When the user clicks on <span> (x), close the modal
128 span.onclick = function() { 
129    ¦modal.style.display = "none";
130 }
131 </script>
132 
133 </body>
134 </html>

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


#35374

FromRobert Heller <heller@deepsoft.com>
Date2018-07-07 21:15 -0500
Message-ID<usqdnRkt2rUx7tzGnZ2dnUU7-U_NnZ2d@giganews.com>
In reply to#35373
At Sat, 7 Jul 2018 21:02:25 -0400 ruben safir <ruben@mrbrklyn.com> wrote:

> 
> Sorry, the code looks line this
> 
>   1 <!DOCTYPE html>
>   2 <html>
>   3 <head>
>   4 <meta name="viewport" content="width=device-width, initial-scale=1">
>   5 <style>
>   6 body {font-family: Arial, Helvetica, sans-serif;}
>   7 
>   8 #myImg {
>   9     border-radius: 5px;
>  10     cursor: pointer;
>  11     transition: 0.3s;
>  12 }
>  13 
>  14 #myImg:hover {opacity: 0.7;}
>  15 
>  16 /* The Modal (background) */
>  17 .modal {
>  18     display: none; /* Hidden by default */
>  19     position: fixed; /* Stay in place */
>  20     z-index: 1; /* Sit on top */
>  21     padding-top: 100px; /* Location of the box */
>  22     left: 0;
>  23     top: 0;
>  24     width: 100%; /* Full width */
>  25     height: 100%; /* Full height */
>  26     overflow: auto; /* Enable scroll if needed */
>  27     background-color: rgb(0,0,0); /* Fallback color */
>  28     background-color: rgba(0,0,0,0.7); /* Black w/ opacity */
>  29 }
>  30 
>  31 /* Modal Content (image) */
>  32 .modal-content {
>  33     margin: auto;
>  34     display: block;
>  35     width: 100%;
>  36     max-width: 700px;
>  37 }
>  38 
>  39 /* Caption of Modal Image */
>  40 #caption {
>  41     margin: auto;
>  42     display: block;
>  43     width: 80%;
>  44     max-width: 700px;
>  45     text-align: center;
>  46     color: #ccc;
>  47     padding: 5px 0;
>  48     height: 150px;
>  49 }
>  50 
>  51 /* Add Animation */
>  52 .modal-content, #caption {
>  53     -webkit-animation-name: zoom;
>  54     -webkit-animation-duration: 0.6s;
>  55     animation-name: zoom;
>  56     animation-duration: 0.6s;
>  57 }
>  58 
>  59 @-webkit-keyframes zoom {
>  60     from {-webkit-transform:scale(0)}
>  61     to {-webkit-transform:scale(1)}
>  62 }
>  63 
>  64 @keyframes zoom {
>  65     from {transform:scale(0)}
>  66     to {transform:scale(1)}
>  67 }
>  68 
>  69 /* The Close Button */
>  70 .close {
>  71     position: absolute;
>  72     top: 15px;
>  73     right: 35px;
>  74     color: #f1f1f1;
>  75     font-size: 40px;
>  76     font-weight: bold;
>  77     transition: 0.3s;
>  78 }
>  79 
>  80 .close:hover,
>  81 .close:focus {
>  82     color: #bbb;
>  83     text-decoration: none;
>  84     cursor: pointer;
>  85 }
>  86 
>  87 /* 100% Image Width on Smaller Screens */
>  88 @media only screen and (max-width: 700px){
>  89     .modal-content {
>  90         width: 100%;
>  91     }
>  92 }
>  93 </style>
>  94 </head>
>  95 <body>
>  96 
>  97 <h2>Image Modal</h2>
>  98 <p>In this example, we use CSS to create a modal (dialog box) that is hidden by default.</p>
>  99 <p>We use JavaScript to trigger the modal and to display the current image inside the modal when it is clicked on. Also note that we use the value from the image's "alt" attr    ibute as an image caption text inside the modal.</p>
> 100 
> 101 <img id="myImg" src="http://www.mrbrklyn.com/images/comics/action_78.jpg" alt="Action Comics" style="width:100%;max-width:300px">
> 102 
> 103 <!-- The Modal -->
> 104 <div id="myModal" class="modal">
> 105   <span class="close">&times;</span>
> 106   <img class="modal-content" id="img01">
> 107   <div id="caption"></div>
> 108 </div>
> 109 
> 110 <script>
> 111 // Get the modal
> 112 var modal = document.getElementById('myModal');
> 113 
> 114 // Get the image and insert it inside the modal - use its "alt" text as a caption
> 115 var lc_img = document.getElementById('myImg');
> 116 var mo = document.getElementById("img01");
> 117 var captionText = document.getElementById("caption");
> 118 lc_img.onclick = function(){
> 119    ¦modal.style.display = "block";
> 120    ¦mo.src = this.src;
                   ^
You mean this------|

> 121    ¦captionText.innerHTML = this.alt;
                                    ^
And this ---------------------------|

The "this" refers to the "lc_img" variable, which is the <img ...> right at 
the beginning.  When that image is clicked on, its src and alt are copied to 
the img and embeded <div> inside the <div id="myModal" class="modal"> tag, and 
the modal div's display style gets changed from none to block. Clicking on the 
now visible close button, changes the div display style back to none. 
   
> 122 }
> 123 
> 124 // Get the <span> element that closes the modal
> 125 var span = document.getElementsByClassName("close")[0];
> 126 
> 127 // When the user clicks on <span> (x), close the modal
> 128 span.onclick = function() { 
> 129    ¦modal.style.display = "none";
> 130 }
> 131 </script>
> 132 
> 133 </body>
> 134 </html>
>                                                                                                                        

-- 
Robert Heller             -- 978-544-6933
Deepwoods Software        -- Custom Software Services
http://www.deepsoft.com/  -- Linux Administration Services
heller@deepsoft.com       -- Webhosting Services
                                                                                                                              

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


#35375

FromJJ <jj4public@vfemail.net>
Date2018-07-08 10:17 +0700
Message-ID<1gpxuw1cx7u1z$.vf2k9gkt8uq0.dlg@40tude.net>
In reply to#35373
On Sat, 7 Jul 2018 21:02:25 -0400, ruben safir wrote:
[snip]
> 101 <img id="myImg" src="http://www.mrbrklyn.com/images/comics/action_78.jpg" alt="Action Comics" style="width:100%;max-width:300px">
> 102 
> 103 <!-- The Modal -->
> 104 <div id="myModal" class="modal">
> 105   <span class="close">&times;</span>
> 106   <img class="modal-content" id="img01">
> 107   <div id="caption"></div>
> 108 </div>
> 109 
> 110 <script>
> 111 // Get the modal
> 112 var modal = document.getElementById('myModal');
> 113 
> 114 // Get the image and insert it inside the modal - use its "alt" text as a caption
> 115 var lc_img = document.getElementById('myImg');
> 116 var mo = document.getElementById("img01");
> 117 var captionText = document.getElementById("caption");
> 118 lc_img.onclick = function(){
> 119    ¦modal.style.display = "block";
> 120    ¦mo.src = this.src;
> 121    ¦captionText.innerHTML = this.alt;
> 122 }
> 123 
> 124 // Get the <span> element that closes the modal
> 125 var span = document.getElementsByClassName("close")[0];
> 126 
> 127 // When the user clicks on <span> (x), close the modal
> 128 span.onclick = function() { 
> 129    ¦modal.style.display = "none";
> 130 }
> 131 </script>
[snip]

It's just like Robert Heller said.

The `this` keyword refers to the object pointed by `lc_img`. In an onXXX
handler function, the `this` keyword by default would refer to the onXXX
property's object - whichever that is.

Consider below code.

  function handler() {
    //...
  }
  theDiv.onclick = handler;
  theSpan.onclick = handler;

The `this` keyword within the `handler` function will vary depending on
which element is being triggered. If `theDiv` was clicked, the `this`
keyword would be equal to `theDiv`. If `theSpan` was clicked, the `this`
keyword would be equal to `theSpan`.

Basically, the `this` keyword value will depend on how a context is created.
IOTW, how a function is called.

At global context, the `this` keyword refers to the global object. In a web
browser, the global object would be the `window` object. So `handler()` is
called directly e.g.

  handler();

Then the `this` keyword would be equal to `window`.

If it's called like below.

  theDiv.onclick();

Then the `this` keyword would be equal to `theDiv`. Basically, the direct
owning object of the called method, which is `theDiv` in above example.

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


#35381

FromJulio Di Egidio <julio@diegidio.name>
Date2018-07-08 04:49 -0700
Message-ID<02349395-15a3-49e3-8c29-ae7fa9c93d22@googlegroups.com>
In reply to#35372
On Sunday, 8 July 2018 02:59:43 UTC+2, ruben safir  wrote:
<snip>
> So line 120 assigns the url for the clicked upon image into the mo.src
> variable and turns it on.  But I would have thought that this would be a
> reference to the document object, not the image that was clicked, so
> I am confused about the rules of object heiarchy.

It's the rules for the 'this' reference, nothing to do with "hierarchies".
And the answers given so far (about 'this') are all just partly correct.

Anyway, maybe you remember that document is the default object in DOM event
handlers, but that's another story.

> Otherwise, how is var mo visible within the function?

That's again another story: 'mo' is captured in the closure of the
function, indeed it's defined and assigned in the immediate outer scope.

HTH,

Julio

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


#35389

Fromruben safir <ruben@mrbrklyn.com>
Date2018-07-08 12:17 -0400
Message-ID<phtde5$oif$1@reader1.panix.com>
In reply to#35372
On 07/07/2018 08:59 PM, ruben safir wrote:
> And the answers given so far (about 'this') are all just partly correct.

Then what is the correct answer :)?

<scratching my head>

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


#35390

FromJulio Di Egidio <julio@diegidio.name>
Date2018-07-08 10:43 -0700
Message-ID<ba5f0abb-9cc4-4527-9bea-8d4a88d9ed4e@googlegroups.com>
In reply to#35389
On Sunday, 8 July 2018 18:17:15 UTC+2, ruben safir  wrote:
> On 07/07/2018 08:59 PM, ruben safir wrote:
<snip>
> > And the answers given so far (about 'this')
> > are all just partly correct.
> 
> Then what is the correct answer :)?

You mean totally correct?  It's read the fine manual.

> <scratching my head>

<https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/this>

Julio

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


#35402

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2018-07-08 22:49 +0200
Message-ID<d072dee2-7ca7-9b96-9b0c-0e52482ec320@PointedEars.de>
In reply to#35389
ruben safir wrote:
> On 07/07/2018 08:59 PM, ruben safir wrote:
>> And the answers given so far (about 'this') are all just partly correct.
> 
> Then what is the correct answer :)?
> 
> <scratching my head>

As always, the one that makes predictions such that those predictions are
able to be falsified, but in experimentation are not falsified or are even
verified.

IOW, the one that can be confirmed using the scientific method.


HTH

PointedEars
-- 
When all you know is jQuery, every problem looks $(olvable).

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


#35404

FromJulio Di Egidio <julio@diegidio.name>
Date2018-07-08 13:55 -0700
Message-ID<9a10ed21-70cf-4e2d-b4bf-21cdf24f9c44@googlegroups.com>
In reply to#35402
On Sunday, 8 July 2018 22:49:28 UTC+2, Thomas 'PointedEars' Lahn  wrote:
> ruben safir wrote:
> > On 07/07/2018 08:59 PM, ruben safir wrote:
> >> And the answers given so far (about 'this') are all just partly correct.
> > 
> > Then what is the correct answer :)?
> > 
> > <scratching my head>
> 
> As always, the one that makes predictions such that those predictions are

You stupid fuck, so precise and you mess up attributions and context.

What fun, a parade of stupid cunts...

*Plonk*

Julio

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


#35392

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2018-07-08 21:51 +0200
Message-ID<204ab6d4-2ee0-8e58-b96c-d59fb6943ca5@PointedEars.de>
In reply to#35372
ruben safir wrote:
> I was reviewing this simple program from the w3schools tutorials and it
> confused me.

Drop out of W3Schools before you hurt yourself and others.  Historically it
has been a Web site full of misinformation – bad, outdated coding habits in
particular –, and it still only cannibalizes on the W3C name (it is _not_
maintained by the W3C).  There is no indication that it has changed
considerably.

Use MDN as primary development resource instead:

<https://developer.mozilla.org/en-US/> (some translations are available there)

It is a wiki, but mostly maintained by competent people instead.

> 118 lc_img.onclick = function(){
> 119    ¦modal.style.display = "block";
> 120    ¦mo.src = this.src;
> 121    ¦captionText.innerHTML = this.alt;
> 122 }

In this case it is acceptable, but avoid posting prefixed code next time.
Nobody can debug such a mess without heavy copy-editing.  Also, you should
*cite* any source (by URI) so that your statements about it can be verified.

> So line 120 assigns the url for the clicked upon image into the mo.src
> variable

No, it sets the “src” _property_ of the _object_ _referred to_ by “mo” to
the _value_ of the “src” _property_ of the object _referred to_ by “this”.
The latter object *represents* the "clicked upon image".

> and turns it on.

No "turning on" happens there at all.

> But I would have thought that this would be a reference to the document
> object,

There is no good reason why “this” should refer to a document object here.
In non-stricht mode, it could refer to a window object; but event listeners
are almost always called as methods of the object they have been added to,
in this case the object referred to by “lc_img”.

And “this” either

  - refers to the object that a function has been called as a method of
    (all modes),

    unless it is strict mode code and the object is a native wrapper
    around a primitive value, in which case it is that primitive value,

  - refers to the global object (non-strict mode) or is the “undefined”
    value (strict mode) if the function has not been called as a method,

  - has the value it has been set to by Function.prototype.call(),
    Function.prototype.apply(), or Function.prototype.bind() [ES 5+],

or

  - in a constructor call, refers to the object that is being
    constructed.

> not the image that was clicked,

That would make no sense.  Probably you are confusing this with the
window.setTimeout() callback, where it should be evident why “this” in the
callback would refer to a window object, or you have been
misinformed/confused by W3CSchools to zse MSDN’s proprietary, obsolete
attachEvent() method instead, which does not follow any reasonable internal
logic.

> so obviously I am confused about the rules of object heiarchy.

Yes.

> Otherwise, how is var mo visible within the function?

As (almost) always, the variable is in the scope chain of the function
execution context.  This has nothing to do with any notion of "object
hierarchy", it is a language feature that is not at all limited to
ECMAScript implementations.  Programming 101.


PointedEars
-- 
Sometimes, what you learn is wrong. If those wrong ideas are close to the
root of the knowledge tree you build on a particular subject, pruning the
bad branches can sometimes cause the whole tree to collapse.
  -- Mike Duffy in cljs, <news:Xns9FB6521286DB8invalidcom@94.75.214.39>

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


#35393

FromJulio Di Egidio <julio@diegidio.name>
Date2018-07-08 13:00 -0700
Message-ID<a35324cc-69eb-4d5a-b7d4-73a19b2783a6@googlegroups.com>
In reply to#35392
On Sunday, 8 July 2018 21:51:33 UTC+2, Thomas 'PointedEars' Lahn  wrote:
> ruben safir wrote:
> > I was reviewing this simple program from the w3schools tutorials and it
> > confused me.
> 
> Drop out of W3Schools before you hurt yourself and others.

And do not answer questions that have already been fully answered, you
other dumb fuck.

> Use MDN as primary development resource instead:
> 
> <https://developer.mozilla.org/en-US/> (some translations are available there)
> 
> It is a wiki, but mostly maintained by competent people instead.

You are a bit confused: they use a wiki as a tool to maintain a collection
of technical specifications.

> There is no good reason why “this” should refer to a document object here.



> In non-stricht mode, it could refer to a window object; but event listeners
> are almost always called as methods of the object they have been added to,
> in this case the object referred to by “lc_img”.
> 
> And “this” either
> 
>   - refers to the object that a function has been called as a method of
>     (all modes),
> 
>     unless it is strict mode code and the object is a native wrapper
>     around a primitive value, in which case it is that primitive value,
> 
>   - refers to the global object (non-strict mode) or is the “undefined”
>     value (strict mode) if the function has not been called as a method,
> 
>   - has the value it has been set to by Function.prototype.call(),
>     Function.prototype.apply(), or Function.prototype.bind() [ES 5+],
> 
> or
> 
>   - in a constructor call, refers to the object that is being
>     constructed.
> 
> > not the image that was clicked,
> 
> That would make no sense.  Probably you are confusing this with the
> window.setTimeout() callback, where it should be evident why “this” in the
> callback would refer to a window object, or you have been
> misinformed/confused by W3CSchools to zse MSDN’s proprietary, obsolete
> attachEvent() method instead, which does not follow any reasonable internal
> logic.
> 
> > so obviously I am confused about the rules of object heiarchy.
> 
> Yes.
> 
> > Otherwise, how is var mo visible within the function?
> 
> As (almost) always, the variable is in the scope chain of the function
> execution context.  This has nothing to do with any notion of "object
> hierarchy", it is a language feature that is not at all limited to
> ECMAScript implementations.  Programming 101.
> 
> 
> PointedEars
> -- 
> Sometimes, what you learn is wrong. If those wrong ideas are close to the
> root of the knowledge tree you build on a particular subject, pruning the
> bad branches can sometimes cause the whole tree to collapse.
>   -- Mike Duffy in cljs, <news:Xns9FB6521286DB8invalidcom@94.75.214.39>

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


#35394

FromJulio Di Egidio <julio@diegidio.name>
Date2018-07-08 13:04 -0700
Message-ID<056c100a-12eb-4dd8-ab77-2fce55cd9105@googlegroups.com>
In reply to#35393
On Sunday, 8 July 2018 22:00:34 UTC+2, Julio Di Egidio  wrote:
> On Sunday, 8 July 2018 21:51:33 UTC+2, Thomas 'PointedEars' Lahn  wrote:
> > ruben safir wrote:
> 
> > > I was reviewing this simple program from the w3schools tutorials and it
> > > confused me.
> > 
> > Drop out of W3Schools before you hurt yourself and others.
> 
> And do not answer questions that have already been fully answered, you
> other dumb fuck.
> 
> > Use MDN as primary development resource instead:
> > 
> > <https://developer.mozilla.org/en-US/> (some translations are available there)
> > 
> > It is a wiki, but mostly maintained by competent people instead.
> 
> You are a bit confused: they use a wiki as a tool to maintain a collection
> of technical specifications.

Posted by mistake, here is the rest, you piece of polluting shit:

> > There is no good reason why “this” should refer to a document object here.

No reason that you know, you fraud, but I had even mentioned that one.

> > In non-stricht mode, it could refer to a window object

Bla bla bla: just RTFM you other resident retard!

*Plonk*

Julio

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


#35401

From"Michael Haufe (TNO)" <tno@thenewobjective.com>
Date2018-07-08 13:48 -0700
Message-ID<f977402c-1f2c-48ff-8bdd-915231e0c485@googlegroups.com>
In reply to#35394
Julio Di Egidio wrote:
> Julio Di Egidio  wrote:

> > You are a bit confused: they use a wiki as a tool to maintain a collection
> > of technical specifications.
> 
> Posted by mistake, here is the rest, you piece of polluting shit:

Damn. Now you've devolved into insulting yourself in the third person.

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


#35403

FromJulio Di Egidio <julio@diegidio.name>
Date2018-07-08 13:51 -0700
Message-ID<b5eacf4c-7477-4b57-87cc-2d57c8b51442@googlegroups.com>
In reply to#35401
On Sunday, 8 July 2018 22:48:21 UTC+2, Michael Haufe (TNO)  wrote:
> Julio Di Egidio wrote:
<snip>
> > Posted by mistake, here is the rest, you piece of polluting shit:
> 
> Damn. Now you've devolved into insulting yourself in the third person.

Nope, you retarded cunt simply can't even read.  Hopeless.

*Plonk*

Julio

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


#35396

From"Christoph M. Becker" <cmbecker69@arcor.de>
Date2018-07-08 22:26 +0200
Message-ID<phts0t$n0u$1@solani.org>
In reply to#35393
On 08.07.2018 at 22:00, Julio Di Egidio wrote:

> On Sunday, 8 July 2018 21:51:33 UTC+2, Thomas 'PointedEars' Lahn  wrote:
>
>> Drop out of W3Schools before you hurt yourself and others.
> 
> And do not answer questions that have already been fully answered, you
> other dumb fuck.

This is Usenet.  Nobody is obliged to read all replies (they may not
even see them), let alone replies by people who are usually forgetting
their good breeding.

-- 
Christoph M. Becker

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


#35399

FromJulio Di Egidio <julio@diegidio.name>
Date2018-07-08 13:44 -0700
Message-ID<3affd009-9fcd-4428-ab77-21f85dd98193@googlegroups.com>
In reply to#35396
On Sunday, 8 July 2018 22:26:10 UTC+2, Christoph M. Becker  wrote:
> On 08.07.2018 at 22:00, Julio Di Egidio wrote:
> > On Sunday, 8 July 2018 21:51:33 UTC+2, Thomas 'PointedEars' Lahn  wrote:
> >
> >> Drop out of W3Schools before you hurt yourself and others.
> > 
> > And do not answer questions that have already been fully answered, you
> > other dumb fuck.
> 
> This is Usenet.

And apparently you don't know any Usenet etiquette.

> Nobody is obliged to

Nobody is obliged to do anything: now that holds for me as well.

IOW, cut the crap: STFU and learn for a change!

HTH,

*Plonk*

Julio

[toc] | [prev] | [standalone]


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


csiph-web