Title: Object causing an undefined error in console
Tags: javascript;ajax;object;undefined;console.log
Question: There wasn't something close enough to this already... at least that my newbie mind could grasp.

I'm just trying to play around creating a global containing object that has methods, and contained within are the instructions to create and use AJAX requests.  I then proceed to create an event listener for a button. I then get the following console output.

```Port: Could not establish connection. Receiving end does not exist. -This was deleted-.net/:1
Uncaught ReferenceError: globOject is not defined script.js:21
Port: Could not establish connection. Receiving end does not exist. -This was deleted-.net/:1
Exception in onResRdy: TypeError: Cannot read property 'htmlRes' of undefined ContentScript.js:84
```

I'm sure I'm doing a lot wrong here. Let me know what additional info I would need to include to get assistance on this.

```var globObject = {
sendToServer: function () {
    alert('you got to me at least!');
    var xhr;
    if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
        xhr=new XMLHttpRequest();
    }
    else {// code for IE6, IE5
        xhr=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xhr.open('POST', 'counterDoc.php', true);
    xhr.send();
},
counterClick: function (counter) {
    alert('you got here!');
    counter += 1;
    this.sendToServer();
}};
var button = document.getElementById('submbut').addEventListener('click',globOject.counterClick(0), true);
```

Comment: typo: `globOject.counterClick(0), true);` should be `globObject.counterClick(0), true);`

Comment: This question appears to be off-topic because it is just a typo.

Comment: Sorry I missed that guys, I'm sad now. :(

Here is the accepted answer: 
Fix the typo I said in comment and also @Bonakid mentioned. ```globOject.counterClick(0), true);``` should be ```globObject.counterClick(0), true);```
Do not use ```globObject.counterClick(0)``` for callback function, use ```globObject.counterClick``` instead. The first one will get called immediately when ```globObject``` is defined.
Do not use ```this.sendToServer();```, use ```globObject.sendToServer();``` instead. ```this``` in the ```counterClick``` method will be ```document.getElementById('submbut')``` which is a HTML element. Add ```console.log(this)``` to  ```counterClick``` and you will see that.


A working demo here

Comment for this answer: WoW! the simplest things. Thank you.

Here is another answer: change this 

```var button = document.getElementById('submbut').addEventListener('click',globOject.counterClick(0)
```

to

```var button = document.getElementById('submbut').addEventListener('click',globObject.counterClick(0)
```

theres a typographical error in this part

```globOject.counterClick(0)
```


{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 2, 'CommentCount': 3, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2013:00:10/24/13', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<javascript><ajax><object><undefined><console.log>', 'Title': 'Object causing an undefined error in console', 'ViewCount': 3554, 'id': 19556025, 'user_AboutMe': None, 'user_AccountId': 2495437.0, 'user_DisplayName': 'jFasaJr', 'user_Reputation': 487.0, 'user_Views': 55.0, 'user_id': 2172006.0}}