Search code examples
javascriptdebuggingobjectreverse-engineering

Reverse-engineer a Javascript object?


I have a Javascript object that I want to pass in more parameters, but the documentation is non-existant. My only option seems to be to reverse engineer the Javascript object to see what parameters and values I can pass in.

For example, I want to see if there is a "zoom" parameter for the object and what values I can pass into the "mapType" parameter:

<script type="text/javascript" src="http://maps.google.com/maps?oe=utf-8&amp;file=api&amp;v=2&amp;key=your-gmap-key"></script>
<script type="text/javascript" src="https://share.findmespot.com/spot-widget/js/SpotMain.js"></script>
<script type="text/javascript">
 var widget = new Spot.Ui.LiveWidget({ renderTo: "spot-live-widget",
   feeds: [ "0Wl3diTJcqqvncI6NNsoqJV5ygrFtQfBB" ],
   height: 400,
   width: 500,
   mapType: "physical"
 });
</script>
<div id="spot-live-widget"/>

Any ideas on how to do that?


Solution

  • Well... you could look at the source...

    Your code leads to https://share.findmespot.com/spot-widget/js/SpotMain.js which leads to https://share.findmespot.com/spot-widget/js/Spot.js, which you unpack using http://jsbeautifier.org/ which shows you that no, it cannot take a 'zoom' parameter in its constructor, but it does have a setZoomAndCenter method

    setZoomAndCenter: function (C) {
        var B = new GLatLngBounds;
        for (var A = 0; A < C.length; A++) {
            B.extend(C[A].getPoint())
        }
        this._map.setZoom(this._map.getBoundsZoomLevel(B));
        this._map.setCenter(B.getCenter())
    },
    

    And from this we can see that it has a 'private' member _map, which has a setZoom method.

    Does this help?

    UPDATE

    The above method was actually a member of Spot.Ui.MapRenderer, not the LiveWidget.

    The MapRenderer is used internally by LiveWidget but is not exposed...