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

  • Home
  • SEARCH
  • 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 9173541
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:36:13+00:00 2026-06-17T16:36:13+00:00

I am trying to get this function to get the correct scope for its

  • 0

I am trying to get this function to get the correct scope for its “this” operator, but no luck. Inside the AssetName = function(options){ code block, I want the “this” to point to the class AssetName. What is it that I am missing? The scope of this right from the beginning is window.

Assetname: function(options){

    var Base = WM.Utility.GenericFilter()
    options = options;

    if (typeof Object.create !== "function") { 
        // For older browsers that don't support object.create
        Object.create = function (o) {
            function F() {}
            F.prototype = o;
            return new F();
        };
    }       

    var AssetName = {};
    AssetName = function(options){
        return function(){
            var self = this;

            debugger;
            // Call the super constructor.
            Base.call(this, options);

            this.$mod.on('change', '#asset-name-quick-search', self, 
                this.search);
            this.$mod.on('click', '.close', self,  this.remove);

            this.initTypeAhead();
            this.$selectionList = this.$mod.find("#asset-name-selection-list");

            this.assetListItems = [];

            return this;    
        }(options, AssetName);

    }

    // The AssetName class extends the base GenericFilter class.
    AssetName.prototype = Object.create(Base.prototype);

    AssetName.prototype.initTypeAhead = function(){
        var options = {};
        options.source = _.pluck(this.collection, 'asset_name');
        options.items = 8;
        this.$mod.find('#asset-name-quick-search').typeahead(options);    
    };

    AssetName(options);
    return AssetName;
},
  • 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-06-17T16:36:14+00:00Added an answer on June 17, 2026 at 4:36 pm
    AssetName = function(options){
            return function(){
                var self = this;
    
                debugger;
                // Call the super constructor.
                Base.call(this, options);
    
                this.$mod.on('change', '#asset-name-quick-search', self,  this.search);
                this.$mod.on('click', '.close', self,  this.remove);
    
                this.initTypeAhead();
                this.$selectionList = this.$mod.find("#asset-name-selection-list");
    
                this.assetListItems = [];
    
                return this;    
            }(options, AssetName);
    
        }
    

    change to

    AssetName = function(options){
            var aa =  function(){
                var self = this;
    
                debugger;
                // Call the super constructor.
                Base.call(this, options);
    
                this.$mod.on('change', '#asset-name-quick-search', self,  this.search);
                this.$mod.on('click', '.close', self,  this.remove);
    
                this.initTypeAhead();
                this.$selectionList = this.$mod.find("#asset-name-selection-list");
    
                this.assetListItems = [];
    
                return this;    
            };
            aa.call(AssetName,options);
    
        }
    

    In your code, the function aa is called as aa(options); so this is window.

    [update]

    I fix the bug with the following code:

    AssetName =  function (options) {
        AssetName = function (options) {
            var aa = function () {
                alert(this);
                return this;
            };
            aa.call(this, options);
        }
        AssetName.prototype.initTypeAhead = function () {
            alert(1);
        }
    
        return new AssetName(options);;
    };
    var test = AssetName();
    test.initTypeAhead();
    

    But I suggest how about writing the code like bellow:

    AssetName =  function (options) {
        AssetName = function (options) {
                alert(this);
        }
        AssetName.prototype.initTypeAhead = function () {
            alert(1);
        }
    
        return  new AssetName();
    };
    var test =  AssetName();
    test.initTypeAhead();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to get this to work, with no luck: [DataMember] public Type ParameterType {
Im trying to get this working but for some reason it's just not right.
I am trying to get this piece of code working in C#, what I
I´m trying to get this to work but it just want... The alert alerts
So I'm trying to get this engine to work, and I did, but it's
I am trying to get this script to work, but it is failing somewhere
So I am trying to get this code below to work with updating a
I'm trying to write a calendar function like this function get_date($month, $year, $week, $day,
Trying to get this expression to work, can someone look at it and tell
Been trying to get this up and running for a while now. Basically i

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.