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);
}
}
}
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---