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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T01:18:16+00:00 2026-06-03T01:18:16+00:00

when im pressing spacebar, chrome shows error: Uncaught TypeError: Object # has no method

  • 0

when im pressing spacebar, chrome shows error: “Uncaught TypeError: Object # has no method ‘Spacebar'”

(firefox does say “this.Spacebar is not a function”);

here is the object, which goes to be initialised by “Init();”(on page load…):

function KeyManager() { 
this.mode="none";

this.Spacebar = ChatManagement.submitMessage;
this.KeyPress = function(e) {
        if(e.keyCode==13) {
            this.Spacebar();
        }
    }
this.switchKeySet= function(value) {
    if(this.mode!=value) {
        this.mode=value;
        switch(value) {
            case "login":
            this.Spacebar = LoginManagement.SendLogin;
            break;
            case "chat":
            this.Spacebar = ChatManagement.submitMessage;
            break;              
            default:
            case "none":
            break;
        }
    document.onkeypress=this.KeyPress;
    }
}

Init function:

function Init() {
ChatManagement = new ChatManager();
LoginManagement= new Login();
KeyManagement= new KeyManager();
KeyManagement.switchKeySet("chat");
}

Chat Management Object:

function ChatManager() {
this.submitMessage = function() {
    $("Message").focus();
    var text = $("Message").value; 
    if(text==""){  
        this.write('<p class="warning">Please enter a message');  
        return;  
    }  
    try{ 
        SendMessage(text);  
        this.write('<p class="event">Sent: '+text)  
    } catch(exception){  
    this.write('<p class="warning"> Error:' + exception);  
    } 
    $("Message").value="";
}

}

“this.submitMessage()” of ChatManager works

when i use “console.log(this.Spacebar);” at end of “switchKeySet();” i get the code of “this.submitMessage()”.

when i use it at start of “this.KeyPress()”, ill get “undefined”;

im trying to avoid multiple switch statements and javascript-libaries which have a function for this case…..

does someone know where the error is?
ive got the feeling, that “this.spacebar” gets the undefined “this.submitMessage” but init initializes ChatManager first and i press spacebar after init is done…

(or isnt it possible to pass functions around like i tried to?) %_%.

  • 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-03T01:18:17+00:00Added an answer on June 3, 2026 at 1:18 am

    The problem here is with the ‘this’ keyword taking a different meaning when you get into the function for this.KeyPress:

    this.Spacebar = ChatManagement.submitMessage; // 'this' refers to the KeyManager function 
    this.KeyPress = function(e) { 
            if(e.keyCode==13) { 
                this.Spacebar(); // 'this' refers to the caller of the function (keypress event)
            } 
        } 
     ....
        document.onkeypress=this.KeyPress;  
      }
    

    Check out the answers to How does the "this" keyword work? for a clearer picture but it looks like you need to change your code to something like:

    function KeyManager() {
    var self = this;      
    self.mode="none";     
    
    self.Spacebar = ChatManagement.submitMessage;     
    self.KeyPress = function(e) {     
            if(e.keyCode==13) {     
                self.Spacebar();     
            }     
        }     
    self.switchKeySet= function(value) {     
        if(self.mode!=value) {     
            self.mode=value;     
            switch(value) {     
                case "login":     
                self.Spacebar = LoginManagement.SendLogin;     
                break;     
                case "chat":     
                self.Spacebar = ChatManagement.submitMessage;     
                break;                   
                default:     
                case "none":     
                break;     
            }     
        document.onkeypress=self.KeyPress;     
        }     
    }     
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is pressing spacebar only way to indent for F# in #light mode? This seems
Pressing enter inside a textbox refreshes the whole page in Google Chrome. please help
Does anyone know of a way to simulate pressing a detail disclosure button?
In Visual Studio I can navigate backwards by pressing Ctrl + - . This
No. Not pressing PRT Screen. But here is what I want. And I need
Problem: I have to design an algorithm, which does the following for me: Say
On Songza you can pause / resume a song by pressing Spacebar . How
when pressing on a button that error comes up in the OUTPUT tab the
I know I can do this by pressing Insert in INSERT mode, but that
Pressing search button in jqgrid toolbar opens advanced search window. Pressing enter key does

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.