Javascript は私が最初に選んだ言語ではありませんし、それほど精通している言語でもありません。機能的なものは問題ありませんが、オブジェクトはそれほど多くありません。
次のシナリオに対処するためのオプションを誰かが提案できるかどうかを確認しています。
function postcodeEntry(destination,postcode) {
    "use strict";
    document.getElementById('googlemappostcode').innerHTML = <?php if ($_GET['page']==="fun") echo "<div id=\"map\"></div>' + ";?>'<form id="postcodeEntry" method="post" action="/" onsubmit="calcRoute(\'driving\',this.postcode.value,' + destination.hb + ',' + destination.ib + ',\'' + postcode + '\');return false;">'
        + '<h2>Get directions</h2>'
        + '<fieldset>'
        + '<input type="hidden" name="action" value="gmap-directions" />'
        + '<p class="where"><a href="/contact/" onclick="geoLoc();return false;">Where am I?</a></p>'
        + '<label for="postcode">Enter your postcode for directions</label>'
        + '<input type="text" name="postcode" id="postcode" onfocus="checkthis(this,\'Your Postcode/Address:\')" onblur="checkthis(this,\'Your Postcode/Address:\')" value="Your Postcode/Address:" />'
        + '<input type="submit" name="submitTravelType" value="Driving" id="gms_driving" onclick="calcRoute(\'driving\',document.getElementById(\'postcode\').value,' + destination.hb + ',' + destination.ib + ',\'' + postcode + '\');return false;" />'
        + '<input type="submit" name="submitTravelType" value="Walking" id="gms_walking" onclick="calcRoute(\'walking\',document.getElementById(\'postcode\').value,' + destination.hb + ',' + destination.ib + ',\'' + postcode + '\');return false;" />'
        + '<input type="submit" name="submitTravelType" value="Public Transport" id="gms_transit" onclick="calcRoute(\'transit\',document.getElementById(\'postcode\').value,' + destination.hb + ',' + destination.ib + ',\'' + postcode + '\');return false;" />'
        + '<input type="submit" name="submitTravelType" value="Cycling" id="gms_bicycling" onclick="calcRoute(\'bicycling\',document.getElementById(\'postcode\').value,' + destination.hb + ',' + destination.ib + ',\'' + postcode + '\');return false;" />'
        + '</fieldset>'
        + '</form>'
        + '<div id="directions"></div>';
}
function initialize() {
    "use strict";
    var contentString, destination, el, entryPanoId, i, image, infowindow, links, mapOptions, panoId, panoOptions, radius, shadow, shape;
    /* Destination becomes a four part array. 1st being lat, 2nd being long, 3rd being a google maps latlng and the 4th being postcode */
    destination = [<?php echo $venue['latlong']?>];
    destination[2] = new google.maps.LatLng(destination[0], destination[1]);
    destination[3] = '<?php echo $venue['postcode']?>';
    postcodeEntry(destination[2], destination[3]);
    directionsService = new google.maps.DirectionsService();
    directionsDisplay = new google.maps.DirectionsRenderer();
    trafficLayer = new google.maps.TrafficLayer();
    streetviewService = new google.maps.StreetViewService();
    ...
初期化関数が呼び出されると、それは少し実行され、マップがうまくなります。郵便番号/場所のエントリは完全に機能します。実際、それはすべて機能しますが、問題はありません。
私の質問は、一部の情報が郵便番号フォームに送信され、そのフォームからの戻り値が geoLoc または calcRoute 関数のいずれかに送られるということです。これはもちろん、初期化関数で設定されたものとの接触が失われることを意味します。
これは、示されているスクリプト セグメント内のすべての項目を含むがこれらに限定されない、かなりの数のグローバル変数を使用する必要があることを意味します。
私はその言語についてもっと学び、その使用に習熟しようとしています。その結果、私は (主に純粋な頑固さから) グローバルを (可能であれば) ゼロにするか、可能な限り少なくしようと思います。
これを解決する方法はありますか?私は JavaScript オブジェクトについてあまり知りませんが、常に学習しているので、どうにかして初期化関数を他のすべてのオブジェクトを含むオブジェクトに変換しますか? (現在、JavaScriptオブジェクトについて私がどれだけ知っているかを考えると、それは実際には完全に狂っているかもしれません)