2

Possible Duplicate:
Static variables in JavaScript

I have a problem with javascript. What I intend to do is to simulate a class named Tooltip. Ex:

var Tooltip = function(){
    this.draw = .....;
    /////////// other members and methods

    this.Static = ...; // this one I want to be static }

The problem is I can't find a method to declare a static method/member. And I presume that the above way doesn't work. Is there any method to simulate a class with a static member? (preferably using object literals)

LE: I forgot to tell that I want to have acces to the static members from an instance of the class.

0

2 Answers 2

3

Javascript is a Prototype language.. It's not C

That being said.. Watch some video's of David Crockford and see if this SO solution fit's your bill.

Good luck!!

Sign up to request clarification or add additional context in comments.

Comments

0

Here you go, tooltip.sam() will be "sam" and you can't change it.

This is called the "Revealing Module Pattern" I believe.

var tooltip = function() {
        var _sam = "sam";


        var sam : function()
           { 
             return _sam;
           }

        return { 
           sam :  sam 
        };
 })();

1 Comment

This is too complex and is not practical, but thanks for the tip.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.