Can I define a static method in the Class.create() method? And how?
I have the follow code in MenuEngine.js file:
var MenuEngine = Class.create({
initialize: function(){
// Initialize lines code
...
}
staticMethod: function(){
// staticMethods lines code
...
}
});
I want write the follow line in other file example.js and I want that
this will work:
MenuEngine.staticMethod()
Thanks.
Lodecesa
--~--~---------~--~----~------------~-------~--~----~
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
rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---
Methods defined in the Class.create({...}) initializer block are not static.
After you create the class, you can do:
MenuEngine.staticMethod = function() { ... }
or
Object.extend(MenuEngine, { ... }) if you have more than one to define.
-Fred
On Tue, May 27, 2008 at 10:12 AM, lodecesa
<lorenzo.decesare-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:
>
> Can I define a static method in the Class.create() method? And how?
>
> I have the follow code in MenuEngine.js file:
>
> var MenuEngine = Class.create({
>
> initialize: function(){
> // Initialize lines code
> ...
> }
>
> staticMethod: function(){
> // staticMethods lines code
> ...
> }
>
> });
>
> I want write the follow line in other file example.js and I want that
> this will work:
>
> MenuEngine.staticMethod()
>
> Thanks.
> Lodecesa
> >
>
--
Science answers questions; philosophy questions answers.
--~--~---------~--~----~------------~-------~--~----~
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
rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---
Or you can use my with pattern I posted the other day :)
var Foo = Class.create();
Object.extend(Foo, {
A_CLASS_CONSTANT: 42,
a_class_method: function() {
}
});
with (Foo) addMethods({
an_instance_method: function() {
alert(A_CLASS_CONSTANT);
a_class_method();
}
});
If you''re with-averse, just change with (Foo) addMethods() to
Foo.addMethods().
On Tue, May 27, 2008 at 10:15 AM, Frederick Polgardy
<fred-SMQUYeM9IBBWk0Htik3J/w@public.gmane.org>
wrote:
> Methods defined in the Class.create({...}) initializer block are not
> static.
>
> After you create the class, you can do:
>
> MenuEngine.staticMethod = function() { ... }
>
> or
>
> Object.extend(MenuEngine, { ... }) if you have more than one to define.
>
> -Fred
>
>
> On Tue, May 27, 2008 at 10:12 AM, lodecesa
<lorenzo.decesare-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
> wrote:
>
>>
>> Can I define a static method in the Class.create() method? And how?
>>
>> I have the follow code in MenuEngine.js file:
>>
>> var MenuEngine = Class.create({
>>
>> initialize: function(){
>> // Initialize lines code
>> ...
>> }
>>
>> staticMethod: function(){
>> // staticMethods lines code
>> ...
>> }
>>
>> });
>>
>> I want write the follow line in other file example.js and I want that
>> this will work:
>>
>> MenuEngine.staticMethod()
>>
>> Thanks.
>> Lodecesa
>> >>
>>
>
>
> --
> Science answers questions; philosophy questions answers.
--
Science answers questions; philosophy questions answers.
--~--~---------~--~----~------------~-------~--~----~
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
rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---