SO 21321157: Google Maps Custom Events

How can I create custom events for google maps api v3 objects?

HTML

<script src="https://maps.googleapis.com/maps/api/js?v=3&amp;sensor=false&amp;libraries=geometry"></script>

JavaScript

function CustomPolygon(options) {
         var self = this;
         // initialize any options
         console.log('init')
     }
	x=true;
     function edit() {
         // do work!!!
         // now tell people about it!
         if (x==true){
          x=false;
         google.maps.event.trigger(this, 'edited');
         }
        
     }
     function edit2() {
         // do work!!!
         // now tell people about it!
         if (x==false){
         x=true;
         google.maps.event.trigger(this, 'edited2');
         }
         
     }

     // extend CustomPolygon from google.maps.Polygon
     CustomPolygon.prototype = new google.maps.Polygon();
     CustomPolygon.prototype.edit = edit;

     // now you can do 
     var p = new CustomPolygon({ /*options*/
     });
     google.maps.event.addListener(p, 'edited', function () {
         document.body.innerHTML = 'edited!';
     });
     
      google.maps.event.addListener(p, 'edited2', function () {
         document.body.innerHTML = 'ss';
     });

     
     p.edit();
     p.edit2();