[JS] Syntaxfout ? Waar dan ?

Pagina: 1
Acties:

  • r0bert
  • Registratie: September 2001
  • Laatst online: 11-08 16:19
Ik heb het volgende stukje code.. Ik geef toe dat het wat onduidelijk lijkt zo, maar het is wel compacter..
JavaScript:
1
2
3
4
5
6
7
strIets = (objEl.firstChild.lastChild.src.indexOf('T') > -1) ? (((bExpand == 1) || 
(bExpand == 0)) ? ((bExpand == 0) ? 'plusT' : ((objEl.lastChild.style.display
== 'block') ? 'minT' : 'plusT')) : ((objEl.lastChild.style.display == 'block') ? 'minT' : 'plusT')) : 
(((bExpand == 1) || (bExpand == 0)) ? 
((bExpand == 0) ? 'plusT' : ((objEl.lastChild.style.display 
== 'block') ? 'minT' : 'plusT')) : ((objEl.lastChild.style.display 
== 'block') ? 'minT' : 'plusT')));

Als ik dit stukje wil gebruiken krijg ik een foutmelding in IE.. eerst syntaxfout, nu krijg ik verwacht ';'

Om het allemaal beetje overzichtelijk te maken heb ik geprobeerd het bovenstaande een beetje duidelijk te structureren in een overzichtje:
HTML:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
(objEl.firstChild.lastChild.src.indexOf('T') > -1)
        ?
        (
            ((bExpand == 1) || (bExpand == 0))
            ?
            (   (bExpand == 0) 
                ?
                'plusT'
                :
                (   (objEl.lastChild.style.display == 'block')
                    ?
                    'minT'
                    :
                    'plusT'
                )
            )
            :
            (   (objEl.lastChild.style.display == 'block')
                ?
                'minT'
                :
                'plusT'
            )
        )
        :
        (   ((bExpand == 1) || (bExpand == 0))
            ?
            (   (bExpand == 0)
                ?
                'plusT'
                :
                (   (objEl.lastChild.style.display == 'block')
                    ?
                    'minT'
                    :
                    'plusT'
                )
            )
            :
            (   (objEl.lastChild.style.display == 'block')
                ?
                'minT'
                :
                'plusT')
            )
        );
---------------------------------------------------------------------------------------------------
    if (objEl.firstChild.lastChild.src.indexOf('T') > -1)
        if ((bExpand == 1) || (bExpand == 0))
            if (bExpand == 1) 'minT'
            else
                if (bExpand == 0) 'plusT'
                else switch display   'minT' : 'plusT'
        else switch display   'minT' : 'plusT'
    else 
        if ((bExpand == 1) || (bExpand == 0))
            if (bExpand == 1) 'minL'
            else
                if (bExpand == 0) 'plusL'
                else switch display   'minL' : 'plusL'
        else switch display   'minL' : 'plusL'

Volgens mij klopt het echt gewoon voor 100% ? Kan misschien iemand helpen de fout te vinden :? want ik heb me echt sufgezocht en kom er niet uit .. Misschien ergens een goede syntaxchecker online ?

[ Voor 13% gewijzigd door r0bert op 02-02-2003 14:14 ]


  • coubertin119
  • Registratie: Augustus 2002
  • Laatst online: 20-08 15:43
in welke regel en op welke kolom vind de error plaats, dan weet je toch al waar er iets fout zit/ontbreekt.

Skat! Skat! Skat!


Verwijderd

Wat is dit? Een gooi naar het WK obscuur coden ofzo? Schrijf het eerst maar eens fatsoenlijk uit. :P En gooi er meteen wat ;'s tussen...

De a?b:c -constructie maakt het er niet echt duidlijker op in dit geval? Waarom uberhaupt gebruiken? Omdat het bytes bespaart?

  • r0bert
  • Registratie: September 2001
  • Laatst online: 11-08 16:19
Blues
Wat is dit? Een gooi naar het WK obscuur coden ofzo? Schrijf het eerst maar eens fatsoenlijk uit. :P En gooi er meteen wat ;'s tussen...
En waar zou ik er volgens jou dan een aantal ;'s tussen moeten hangen ? het 2e stukje code is psuedo heh, dus alleen om het overzicht weer te geven.
De a?b:c -constructie maakt het er niet echt duidlijker op in dit geval? Waarom uberhaupt gebruiken? Omdat het bytes bespaart?
Omdat mensen het dan over het algemeen moeilijker kunnen lezen/stelen.. maar als je zelf een overzichtje van de structuur hebt, is het voor jezelf niet erg veel minder duidelijk..

  • hobbit_be
  • Registratie: November 2002
  • Laatst online: 04-07-2025
is het voor jezelf niet erg veel minder duidelijk..
maar je wil wel dat wij dan door zo'n onleesbare code liggen te 'moosen'...

sorry maar help liever mensen met 'echte' problemen.

(no offence)

  • crisp
  • Registratie: Februari 2000
  • Laatst online: 00:19

crisp

Devver

Pixelated

nofi hoor, maar obfuscaten doe je normaal pas als je eerst een werkend stuk code hebt ;)

Intentionally left blank


Verwijderd

achter de laatste plusT zit een ) teveel volgens mij
simpel checken toch?

bij het 2e voorbeeld iig

[ Voor 16% gewijzigd door Verwijderd op 02-02-2003 22:16 ]


  • Spider.007
  • Registratie: December 2000
  • Niet online

Spider.007

* Tetragrammaton

JavaScript:
1
2
3
4
5
6
7
8
9
10
11
var a = objEl.firstChild.lastChild.src.indexOf('T');
var b = ((bExpand == 1) || (bExpand == 0));
var c = (objEl.lastChild.style.display == 'block');
var d = (objEl.lastChild.style.display == 'block');
var e = ((bExpand == 1) || (bExpand == 0));
var f = (objEl.lastChild.style.display == 'block');
var g = (objEl.lastChild.style.display == 'block');

strIets = (a > -1) ? ( b ? ((bExpand == 0) ? 'plusT' : 
(c ? 'minT' : 'plusT')) : (d ? 'minT' : 'plusT')) : (e ? 
((bExpand == 0) ? 'plusT' : (f ? 'minT' : 'plusT')) : (g ? 'minT' : 'plusT')));
Versie 2:
JavaScript:
1
2
3
4
5
6
7
8
var a = objEl.firstChild.lastChild.src.indexOf('T');
var b = ((bExpand == 1) || (bExpand == 0));
var c = (objEl.lastChild.style.display == 'block');

strIets = (a > -1) ? ( b ? ((bExpand == 0) ? 'plusT' : 
(c ? 'minT' : 'plusT')) : (c ? 'minT' : 'plusT')) : (b ?
 ((bExpand == 0) ? 'plusT' : (c ? 'minT' : 'plusT')) 
: (c ? 'minT' : 'plusT')));
Versie 3:
JavaScript:
1
2
3
4
5
6
7
8
var a = objEl.firstChild.lastChild.src.indexOf('T');
var b = ((bExpand == 1) || (bExpand == 0));
var c = (objEl.lastChild.style.display == 'block');

var va = ((bExpand == 0) ? 'plusT' : (c ? 'minT' : 'plusT'));
var vb = (c ? 'minT' : 'plusT');

strIets = (a > -1) ? (b ? va:vb):(b ? ((bExpand == 0) ? 'plusT' : vb):vb));


zo te zien een haakje teveel gesloten; dit zou moeten werken:

JavaScript:
1
2
3
4
5
6
7
strIets = (objEl.firstChild.lastChild.src.indexOf('T') > -1) ? (((bExpand == 1) || 
(bExpand == 0)) ? ((bExpand == 0) ? 'plusT' : ((objEl.lastChild.style.display
== 'block') ? 'minT' : 'plusT')) : ((objEl.lastChild.style.display == 'block') ? 'minT' : 'plusT')) : 
(((bExpand == 1) || (bExpand == 0)) ? 
((bExpand == 0) ? 'plusT' : ((objEl.lastChild.style.display 
== 'block') ? 'minT' : 'plusT')) : ((objEl.lastChild.style.display 
== 'block') ? 'minT' : 'plusT'));


of heb ik hem onderhand al kapoet gemaakt?

[ Voor 255% gewijzigd door Spider.007 op 02-02-2003 22:34 ]

---
Prozium - The great nepenthe. Opiate of our masses. Glue of our great society. Salve and salvation, it has delivered us from pathos, from sorrow, the deepest chasms of melancholy and hate


  • r0bert
  • Registratie: September 2001
  • Laatst online: 11-08 16:19
Joah!! :D

Hij doet het! Erg handig gedaan vind ik zelf zoals spider.007 het heeft gedaan! Dat ik daar zelf niet op kwam! Ik had het intussentijd zelf opgelost door de processen min OF plus en T of L op te splitsen en dan weer aan elkaar te plakken, maar dan moet je eigenlijk ook weten wat het nut is van het scriptje (onderdeel van het in en uitklappen van een tree)

Zoals het bij mij is geworden:
JavaScript:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
alert(

(objEl.firstChild.lastChild.src.indexOf('T') > -1)
?
(
  ((bExpand == 1) || (bExpand == 0))
  ?
  (
        (bExpand == 0)
        ?
        'plusT'
        : 
        (
             (objEl.lastChild.style.display == 'block')
             ?
             'minT'
             :
             'plusT'
         )
   )
   : 
   (
        (objEl.lastChild.style.display == 'block')
        ?
        'minT'
        :
        'plusT'
    )
)
:
(
    ((bExpand == 1) || (bExpand == 0))
    ?
    (
         (bExpand == 0)
         ?
         'plusL' 
         :
         (
               (objEl.lastChild.style.display == 'block') 
               ?
               'minL'
               :
               'plusL'
          )
     )
     :
     (
           (objEl.lastChild.style.display == 'block')
           ?
           'minL'
           :
           'plusL'
     )
)

); //einde alert

JavaScript:
1
2
3
4
5
6
alert((objEl.firstChild.lastChild.src.indexOf('T') > -1) ? (((bExpand == 1) ||
 (bExpand == 0)) ? ((bExpand == 0) ? 'plusT' : 
((objEl.lastChild.style.display== 'block') ? 'minT' : 'plusT')) : 
((objEl.lastChild.style.display == 'block') ? 'minT' : 'plusT')) : (((bExpand == 1) 
|| (bExpand == 0)) ? ((bExpand == 0) ? 'plusL' : ((objEl.lastChild.style.display == 'block') 
? 'minL' : 'plusL')) : ((objEl.lastChild.style.display == 'block') ? 'minL' : 'plusL')));

Iedereen bedankt!!
En ik zal in het vervolg jullie niet meer lastigvallen met syntaxproblemen, want ik geloof dat dat niet gewaardeerd wordt ;) :P

[ Voor 75% gewijzigd door r0bert op 02-02-2003 23:37 ]

Pagina: 1