1
const finder = new FinderClass();    
const gallery1 = new GalleryClass(finder);
const gallery2 = new GalleryClass(finder);

There is a "search" method on finder: finder.search(query). When I call "search" how do I know whether the caller is gallery1 or gallery2?

var GalleryClass = function(finder) {
    this._finder = finder;
}

GalleryClass.prototype = {
    doSearch(query) {
        return this._finder.search(query);
    }
}
SmaGal
  • 135
  • 9
karolis2017
  • 2,195
  • 8
  • 24
  • 49
  • Can you please show how your classes looks like. And what happens to argument(`finder`) passed to `GalleryClass` – Maheer Ali Apr 17 '19 at 02:58
  • 1
    It's better if you reconsider your application design: there is almost never a good reason to find a caller unless you're implementing a tracing/debuggin/or alike tool. – zerkms Apr 17 '19 at 03:03
  • Maybe this could help: https://stackoverflow.com/questions/42870307/getting-the-object-variable-name-in-javascript – SmaGal Apr 17 '19 at 03:09

0 Answers0