javascript - Add an object to a var div element -
so creating "googlemap component" within single page application.
i have been given patterns follow inspired as2 expert. wants have instances of googlemaps available spa. of goals of pattern are, of course, encapsulation , reusability.
the pattern goes follows:
googlemap = { instances: [] }; //static instance,wrapper class googlemap.get = function () { var mapcanvas = document.createelement('div'); if (this.instances.length > 0) { homecoming this.instances.pop(); } var map = new google.maps.map(mapcanvas, mapoptions); //mapoptions defined don't worry homecoming mapcanvas; } googlemap.destroy = function (googlemap) { this.instances.push(googlemap); } then in html:
<script type="text/javascript"> function start() { var mapdiv = googlemap.get(); document.body.appendchild(mapdiv); //here lies issue //mapdiv.setmapcenter({ lat: 90, long: 90 }); } window.onload = start; </script> i want able add together object mapdiv html element right now. thought vars in javascript inherit object except null , undefined. thought do, in googlemap.get:
var mapcanvas = document.createelement('div'); mapcanvas.prototype.setmapcenter = function(lat,long){ //error no prototype! var location = new google.maps.latlng(lat,long); this.instance.setcenter(location); homecoming mapcanvas, has method caller can utilize set lat , long, awesome! if worked way mind thinking } but there no prototype var mapcanvas <div>
javascript
No comments:
Post a Comment