我不知道';我无法通过原型理解javascript的这一部分
我目前正在使用带有prototype.js的cakephp开发google map api V3。我有一个名为:我不知道';我无法通过原型理解javascript的这一部分,javascript,cakephp-1.3,prototypejs,Javascript,Cakephp 1.3,Prototypejs,我目前正在使用带有prototype.js的cakephp开发google map api V3。我有一个名为:TravelMapprManager的javascript类,它有4个类变量和18个函数 var TravelMapprManager = Class.create( { // id of container map_container : '', /* the current map */ map : null, /* geocoding locat
TravelMapprManager
的javascript类,它有4个类变量和18个函数
var TravelMapprManager = Class.create( {
// id of container
map_container : '',
/* the current map */
map : null,
/* geocoding location */
geocoder : null,
/* user entered locations */
user_journey : new Array(),
//many other functions [.....]
initialize : function( map_container ) {
this.map_container = map_container;
// start the map
Event.observe( window, 'load', this.displayMap.bind(this) );
// observe the map buttons
Event.observe( document, 'dom:loaded', this.initObservers.bind(this) );
},
/*
* Save the location entered
*/
findLocation : function() {
location_name = $( 'LocationName' ).value;
if ( location_name == '' ) {
alert( "Please enter a location name." );
return;
}
// we only allow a maximum number of locations
if ( this.user_journey.length >= 20 ) {
alert( "Sorry! We have reached the maximum number of locations." );
return;
}
// Do geocoding, find the longitude and latitude of the location
if ( this.geocoder ) {
var current_o = this;
this.geocoder.getLatLng(
location_name,
function( point ) {
if ( !point ) {
alert( location_name + " not found" );
} else {
// store the location
current_o.storeLocation( location_name, point );
// center the location on the map and add push pin marker
current_o.map.setCenter( point, 13 );
var marker = new GMarker( point );
current_o.map.addOverlay( marker );
}
}
);
}
}
})
什么是
var current\u o=这个代码>函数查找位置中的平均值?此
函数内部的查找位置
与内部函数中的此
关键字不同:
var current_o = this; //<-- Store reference to the `this` keyword inside the func
...
this.geocoder.getLatLng(
location_name,
function( point ) { //<------------
....
事件侦听器中的this
关键字指的是它们绑定到的元素。在示例中,第一个此
引用元素输入[0]
,而第二个此
引用输入[1]
。当您不将第一个this
存储在临时变量(firstElement
)中时,您将无法引用前面的this
(如果不通过document.getElements直接引用第一个元素..
).此
内部函数查找位置
与内部函数中的此
关键字不同:
var current_o = this; //<-- Store reference to the `this` keyword inside the func
...
this.geocoder.getLatLng(
location_name,
function( point ) { //<------------
....
事件侦听器中的this
关键字指的是它们绑定到的元素。在示例中,第一个此
引用元素输入[0]
,而第二个此
引用输入[1]
。当您不将第一个this
存储在临时变量(firstElement
)中时,您将无法引用前面的this
(如果不通过document.getElements直接引用第一个元素..
)。这是必要的,因为This
的引用在该函数中可能不同-这取决于它在getLatLng
中的调用方式。它将This
绑定到局部变量,以便可以在传递给getLatLng
的匿名函数中使用该对象。这是必要的,因为This
的引用在该函数中可能不同-这取决于它在getLatLng
中如何调用