Object has no method Javascript
I don't know why I am getting this problem. I have used prototype before in javascript and it works fine but for some reason it is not working here:
test.html:
<script type="text/javascript">
$(document).ready(function(){
UserOptions("test");
});
</script>
UserOptions.js:
function UserOptions(username){
...
var userOptions = document.createElement("div");
userOptions.className = "userOptions";
**this.createBtns(userOptions);**
userContainer.appendChild(userOptions);
contentCenter.appendChild(userContainer);
contentCenter.appendChild(br);
BuddyList();
}
UserOptions.prototype = {
createBtns:function(parent){
var self = this;
/* Add Buddy Button */
var addBtnContainer = document.crea开发者_StackOverflow中文版teElement("div");
addBtnContinaer.className = "addBtnContainer";
...}
I keep getting the error Object has no method 'createBtns'
You forgot the new
keyword. Now it's trying to call your constructor as a regular function, and this will point to window
or whatever.
new UserOptions("Fred");
精彩评论