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


Groups > de.comp.lang.javascript > #4951

Re: not a function

From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Newsgroups de.comp.lang.javascript
Subject Re: not a function
Date 2018-05-05 01:00 +0100
Organization PointedEars Software (PES)
Message-ID <1838037.LxM6AK9ugR@PointedEars.de> (permalink)
References <pbppha$jg2$1@news.albasani.net> <5377515.lOV4Wx5bFT@PointedEars.de> <pbrqbl$7tr$1@news.albasani.net> <539875bf-65c8-5053-b515-7a6491782f61@PointedEars.de> <pccd3q$j3$1@news.albasani.net>

Show all headers | View raw


Jan Novak wrote:

> Am 29.04.18 um 01:30 schrieb Thomas 'PointedEars' Lahn:
>> […]  Allenfalls wäre noch
>> 
>>    (function () {
>>      var treeView;
        ^^^^^^^^^^^^^ 
>>      $.getJSON(… + '/include/fetch_doc_groups.php',
>>        function (data) {
>>          treeView = $('#treeview-selectable').treeview({
            ^^^^^^^^^^
>>            data: data,
>>            […]
>>          });
>>        });
>> 
>>       /* … treeView … */
>>     }();
          ^ 
>> sinnvoll, wenn Du die Referenz auf den TreeView später noch brauchst.

Korrektur:

Das ist *so* _nicht_ sinnvoll, denn wie schon gezeigt wird “treeView” erst
im Callback initialisiert.  Alle direkten Zugriffe auf treeView bzw. das 
damit referenzierte Objekt müssen daher im Callback, in vom Callback aus 
initiallisierten oder im Callback definierten Funktionen erfolgen.  Sogar 
“continuous polling” sollte im Callback initiiert werden.

Damit kann “treeView” eine im Callback lokale Variable bleiben.

Ausserdem ist das Module Pattern zwar sinnvoll, um globale Variablen zu 
vermeiden, aber ich habe vor dem Semikolon noch eine schliessende runde 
Klammer vergessen.
 
> wahooo.. das macht die ganze Sache etwas deutlicher.
> Mal sehen, wie ich das weiter umsetzen werde.
> Danke.

Bitte.

-- 
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.

Back to de.comp.lang.javascript | Previous | NextPrevious in thread | Find similar


Thread

not a function Jan Novak <repcom@gmail.com> - 2018-04-25 13:41 +0200
  Re: not a function Sascha Hüdepohl <news@juenger-der-himmlischen-teekanne.de> - 2018-04-25 17:49 +0200
    Re: not a function Jan Novak <repcom@gmail.com> - 2018-04-26 07:39 +0200
  Re: not a function Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2018-04-25 21:04 +0200
    Re: not a function Jan Novak <repcom@gmail.com> - 2018-04-26 07:55 +0200
      Re: not a function "Peter J. Holzer" <hjp-usenet3@hjp.at> - 2018-04-28 19:50 +0200
      Re: not a function Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2018-04-29 01:14 +0200
    Re: not a function Jan Novak <repcom@gmail.com> - 2018-04-26 08:07 +0200
      Re: not a function Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2018-04-29 01:30 +0200
        Re: not a function Jan Novak <repcom@gmail.com> - 2018-05-02 15:06 +0200
          Re: not a function Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2018-05-05 01:00 +0100

csiph-web