Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1001167
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T07:37:36+00:00 2026-05-16T07:37:36+00:00

I am defining this class: function GMap(map, marker, geocoder) { this.map = map; this.marker

  • 0

I am defining this class:

function GMap(map, marker, geocoder) {
    this.map = map;
    this.marker = marker;
    this.geocoder = geocoder;

    this.setMarker = function(address) {
        this.geocoder.geocode({'address' : address}, function(results, status) {
            map.setCenter(results[0].geometry.location);
            marker.setPosition(results[0].geometry.location);
        });
    }
}

How can you access the map and marker properties of GMap from the callback function?

Thanks a lot.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T07:37:36+00:00Added an answer on May 16, 2026 at 7:37 am

    The Function object prototype has an “apply” method that you can use to set the context of “this” within a function. Check the API/code for whatever geocoder.code is, many libraries will handle this for you through an extra parameter, i.e.:

    this.someObj.someFn(params, callback, scope);
    

    Within someFn, it would use the callback similarly to this:

    callback.apply(scope || window, [callbackArg1, callbackArg2]);
    

    This would make the “this” context within “callback” whatever had been passed in as “scope”, or if nothing was passed in, “this” would be the global context of the window. Some javascript libraries also provide a way to create a callback function delegate that ensures the function is always called with the expected scope no matter where it ends up being called from. An example of this is ExtJS’s Function.createDelegate

    If the library you are using doesn’t provide this as built in functionality, then you can create a local var to reference within your callback closure, i.e.:

    this.setMarker = function(address) {
        var thisGMap = this;
        this.geocoder.geocode({'address' : address}, function(results, status) {
            thisGMap.map.setCenter(results[0].geometry.location);
            thisGMap.marker.setPosition(results[0].geometry.location);
        });
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am defining a class in javascript using this... // file_a.js function class_a() {
Possible Duplicate: Two css files defining same class The answers to this question and
If I run the function below before defining it, I will get this error...
This problem is in defining and declaring a function template in a namespace that
I'm defining a class like this: class StaticRuntimeContext { public: enum Verbosity { kHIGH,
Let's imagine something like this: class MyTable extends Doctrine_Table { public function construct() {
I´ve defined a class like this: function Class1(){ function Func1(){ /* Methods and vars
When Defining a constructor in a class I initially had something like: public function
I've got form class where I'm defining some inputs, something liek this: class User
I am defining this function in one of my classes: public function onUse():void {};

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.