DIV CSS 佈局教程網

 DIV+CSS佈局教程網 >> 網頁腳本 >> JavaScript入門知識 >> JavaScript基礎知識 >> js對象內部訪問this修飾的成員函數示例
js對象內部訪問this修飾的成員函數示例
編輯:JavaScript基礎知識     

用wrapper封裝這樣在對象內外都可以訪問

復制代碼 代碼如下:
function MapPool(){

 function createMarker(name, lat, lng, state){
  var marker = new AMap.Marker({
   position : new AMap.LngLat(lng, lat),
        });
  //the function mapMoveTo is not accessible here too
        AMap.event.addListener(marker, "click",function(e){
   //moveMapTo(key, name, state)
   //or this.moveMapTo(key, name, state) will raise a unresolved function error
   //you should write wrapper function as a member variable
            _mapMoveTo(key, name, state);
        });
 }

 var _mapMoveTo = function(key, name, state){
  //TODO
 }

 this.mapMoveTo = function(key, name, state) {
  _mapMoveTo(key, name, state);
 }
}

XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved