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 5849971
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T13:04:32+00:00 2026-05-22T13:04:32+00:00

im struggling with a script where a method/object returns undefined var Lang = new

  • 0

im struggling with a script where a method/object returns undefined

var Lang = new function(){
    this.get = function(str, trans){
        if(TRANSLATE[str]){
            var str = TRANSLATE[str][LANG];
            if(count_obj(trans) > 0){
                for(var key in trans){
                    str = str.replace('%'+key+'%', trans[key]);
                }
            }

            return str;
        }
    };
};

function Language(){
    this.tbl_list = null;

    this.append = function(string, obj, index){
        var row = $('<tr></tr>')
            .append('<td class="list_row">'+js2txt(string)+'</td>');

        for(var key in obj){
            row.append('<td class="list_row">'+js2txt(obj[key])+'</td>');
        }
        var td = $('<td class="list_row"></td>').appendTo(row);
        //var inp_edit = $('<input type="button" value="'+Lang.get('BTN_EDIT')+'" />');
        alert(Lang.get);
        List.append_row(row, this.tbl_list, index);
    };
};
alert(Lang.get);

inside the Language object Lang.get returns undefined, but outside it returns the function!?

  • 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-22T13:04:33+00:00Added an answer on May 22, 2026 at 1:04 pm
    > var Lang = new function(){
    >     this.get = function(str, trans){
    >         if(TRANSLATE[str]){
    >             var str = TRANSLATE[str][LANG];
    >             if(count_obj(trans) > 0){
    >                 for(var key in trans){
    >                     str = str.replace('%'+key+'%', trans[key]);
    >                 }
    >             }
    >             return str;
    >         }
    >     }; };
    

    I don’t see a reason for using new above, it’s just a waste of resources. Since Lang doesn’t seem to be called as a constructor, it should, by convention, start with a lower case letter. Why not:

    var lang = {
        get: function(str, trans) {
            // function body
        }
    };
    

    .

    > function Language(){
    >     this.tbl_list = null;
    > 
    >     this.append = function(string, obj, index){
    >     /* snip */
    >         alert(Lang.get);
    >     /* snip */
    >     }; };
    
    
    alert(Lang.get);  // shows source of Lang.get
    

    inside the Language object Lang.get returns undefined, but outside it returns the function!?

    How are you calling it? It appears to be a constructor, so:

    var x = new Language();  // Create instance lf Language
    x.append();  // Shows Lang.get
    

    Which is the same result as calling Language as a function. What is the issue?

    Also, the jQuery stuff seems to be very inefficient. You might want to work on that. e.g.

    > var row = $('<tr></tr>')
    >             .append('<td class="list_row">'+js2txt(string)+'</td>');
    

    would be much better as:

    var row = $('<tr><td class="list_row">'+js2txt(string)+'</td></tr>');
    

    Or even better would be to create a single row with the structure you want, clone it for each row, then just replace the content of the cell.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am struggling to get this simple PowerShell script to work. I have googled,
I have been struggling to get this grid to populate. This returns my 2
I'm currently struggling to get a WebDesignersWall script to function properly on my website.
I'm struggling with some Javascript in my first rails application. Partial: _care_point.html.erb <script> $(function()
I am new to MVC architecture and I am struggling to get the Button
I'm struggling to get NAnt's script task to pick up a reference to a
I have been struggling with this jQuery Validation Plugin. Here is the code: <script
Right now I'm struggling to get this simple PHP AJAX request to work. <html>
Been struggling with this simple selector problem a couple of hours now and must
im struggling with syntax here: hopefully this question is v simple, im just miising

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.