0

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.createElement("div");
            addBtnContinaer.className = "addBtnContainer";
    ...}

I keep getting the error Object has no method 'createBtns'

6
  • Could you also post the line where you try to create the object? Commented Feb 5, 2011 at 3:58
  • Where and when do you get this error? Commented Feb 5, 2011 at 3:59
  • I get the error on the line : this.createBtns(userOptions); I bolded it Commented Feb 5, 2011 at 4:01
  • @Twidizle: Yes, I can see that line, but I want the line where you try to create an instance of UserOptions. Commented Feb 5, 2011 at 4:02
  • 1
    You realize that the last line of "creteBtns" has a misspelling, right? Commented Feb 5, 2011 at 4:04

1 Answer 1

11

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");
Sign up to request clarification or add additional context in comments.

4 Comments

ty... I forgot that prototype makes javacript "object oriented"
@Twidizle: You might want to start marking good answers on your questions as accepted (green tick mark next to the score). I see you haven't marked any accepted answers on your previous ones.
@Twidizle new is not a prototype thing. It's a Javascript thing.
More accurately, prototype makes javascript more class oriented -- javascript is objected oriented already.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.