I’m trying to define my own function in Sencha Touch 2 and I’m still getting an error:
Uncaught ReferenceError: function22 is not defined
And my file responsible for this is: Position.js in View directory
Ext.define('GS.view.Position', {
extend: 'Ext.Map',
xtype: 'map',
config: {
title: 'Position',
iconCls: 'time',
useCurrentLocation:true,
mapOptions: {
zoom: 19
},
listeners: {
maprender : function(comp, map){
//new google.maps.LatLng,
marker = new google.maps.Marker({
position: new google.maps.LatLng(this._geo.getLatitude(), this._geo.getLongitude()),
title: '1',
map: map
});
google.maps.event.addListener(marker, 'click', function22);
new google.maps.Marker({
position: new google.maps.LatLng(51.266064,15.562048),
title: '1',
map: map
});
}
}
},
function22: function(){
alert('some alert');
}
});
Sencha touch is only Javascript! Everything that is true for Javascript will work with sencha touch too!
This is how did solve this problem:
In html, before inserting any other javascript, I write this line:
MYGLOBALOBJECTis an aray with 2 items, named v and f.MYGLOBALOBJECT.vis a hash where I can store all my variables like this:Since in Javascript functions are just another type of variable, you can also store funktions in this global object, this is what I use
MYGLOBALOBJECT.ffor:You can use this function everywhere in your code like this:
Since
MYGLOBALOBJECTi defines outside any curly bracket, it is a global object, and you can use it whereever you want.