Oops, slightly wrong for the static members... in my example you can access
the static members like this:
myClass.prototype.publicStaticMethod();
BUT, this is probably not what most people would like to write. So just use
two declarations (one for static members, and the other for the class level
stuff)
Using Cristophe's example:
Object.extend(myClass, {
publicStaticProperty: "this is public & static",
publicStaticMethod: function() { alert("public static method"); }
});
And then my way if you'd like to use truly private / public paradigm for the
class level stuff:
myClass.prototype = {
initialize: function() {
// ... what I put in here in my first post ...
}
}
On 3/12/07, Ryan Gahl <[EMAIL PROTECTED]> wrote:
>
> Christophe is right. Here is an example of how I would right a class that
> has private variables, public properties, private & public instance methods,
> and public static methods (where applicable I will highlight multiple ways
> to achieve the same thing). Note: by placing the definition of public
> properties and methods within the class's constructor, you guarantee that
> those are instance level members.
>
> myClass = Class.create();
> myClass.prototype = {
>
> // public static members
> publicStaticProperty1: "this is a public static property",
> publicStaticMethod: function () { alert("this is a public static method");
> },
>
> // constructor
> initialize: function (initProp1, initProp2) {
>
> // private variables
> var someVar = "this is private";
>
> // private methods
> function privateFunction() { alert("private method"); }
>
> // public instance properties
> this.publicInstanceProperty1 = "this property is public and only available
> to instances";
>
> // public instance methods (obviously has access to all private members)
> this.publicInstanceMethod = function() {
> alert(someVar);
> privateFunction();
> alert(this.publicInstanceProperty1 );
> }
> }
> }
>
--
Ryan Gahl
Application Development Consultant
Athena Group, Inc.
Inquire: 1-920-955-1457
Blog: http://www.someElement.com
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Spinoffs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---