Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Move Prototype's Function Outside?

Reply
Thread Tools

Move Prototype's Function Outside?

 
 
VUNETdotUS
Guest
Posts: n/a
 
      12-04-2007
How do I place a function outside of the, so called, "class" in
prototype.js?

Example: Here is a standard way to write a class using prototype.js.

var Person = Class.create({
initialize: function(name) {
this.name = name;
},
say: function(message) {
return this.name + ': ' + message;
}
});

I want the function "say" to be outside of class like:

var Person = Class.create({
initialize: function(name) {
this.name = name;
},
say : sayOutside // <-------moved out
});

function sayOutside(message) {
return this.name + ': ' + message;
}
 
Reply With Quote
 
 
 
 
RobG
Guest
Posts: n/a
 
      12-04-2007
On Dec 5, 6:27 am, VUNETdotUS <vunet...@gmail.com> wrote:
> How do I place a function outside of the, so called, "class" in
> prototype.js?


Questions specifically related to features or usage of particular
libraries are off-topic here, you should try a Prototype.js news
group, e.g.:

<URL: http://groups.google.com.au/group/ru...s?hl=en&lnk=li
>


Also, it matters a great deal which version of Prototype.js you are
using - the Class object was changed significantly in version 1.6 in
an attempt to model classic OO inheritance.

You will need to specify whether you want to retain the inheritance
features, or circumvent them.

>
> Example: Here is a standard way to write a class using prototype.js.
>
> var Person = Class.create({
> initialize: function(name) {
> this.name = name;
> },
> say: function(message) {
> return this.name + ': ' + message;
> }
>
> });
>
> I want the function "say" to be outside of class like:
>
> var Person = Class.create({
> initialize: function(name) {
> this.name = name;
> },
> say : sayOutside // <-------moved out
>
> });
>
> function sayOutside(message) {
> return this.name + ': ' + message;
>
> }


You can use Object.extend, something like:

Object.extend(Person, {say: sayOutside});

but it simply copies properties and values from one objet to another,
which to me just makes it obfuscation and is no different to:

Person.say = sayOutside;

but you may want to use:

Person.prototype.say = sayOutside;

Whatever.


--
Rob
 
Reply With Quote
 
 
 
 
VUNETdotUS
Guest
Posts: n/a
 
      12-05-2007
On Dec 4, 4:22 pm, Randy Webb <HikksNotAtH...@aol.com> wrote:
> VUNETdotUS said the following on 12/4/2007 3:27 PM:
>
> > How do I place a function outside of the, so called, "class" in
> > prototype.js?

>
> You go to one of the prototype forums (search the archives) and ask
> someone who supports it how to do what you want.
>
> --
> Randy
> Chance Favors The Prepared Mind
> comp.lang.javascript FAQ -http://jibbering.com/faq/index.html
> Javascript Best Practices -http://www.JavascriptToolbox.com/bestpractices/


I'll try their forums. However I thought Prototype is just a JS with
functions and methods to simplify stuff. I wonder how do JS experts
treat prototype anyway?
 
Reply With Quote
 
David Mark
Guest
Posts: n/a
 
      12-05-2007
On Dec 5, 11:25 am, VUNETdotUS <vunet...@gmail.com> wrote:
> On Dec 4, 4:22 pm, Randy Webb <HikksNotAtH...@aol.com> wrote:
>
> > VUNETdotUS said the following on 12/4/2007 3:27 PM:

>
> > > How do I place a function outside of the, so called, "class" in
> > > prototype.js?

>
> > You go to one of the prototype forums (search the archives) and ask
> > someone who supports it how to do what you want.

>
> > --
> > Randy
> > Chance Favors The Prepared Mind
> > comp.lang.javascript FAQ -http://jibbering.com/faq/index.html
> > Javascript Best Practices -http://www.JavascriptToolbox.com/bestpractices/

>
> I'll try their forums. However I thought Prototype is just a JS with
> functions and methods to simplify stuff. I wonder how do JS experts
> treat prototype anyway?


Like a red-headed stepchild.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
member function swap vs std::move m0shbear C++ 6 02-07-2012 02:02 PM
Writing move constructors and move assignment Andrew Tomazos C++ 2 12-12-2011 01:45 PM
How to move optparse from main to function? Bob Python 5 02-25-2006 12:02 AM
I am trying to move spaces to a weblistbox and when I move them... Eduardo78 ASP .Net Web Controls 0 11-03-2005 06:06 PM
write a function such that when ever i call this function in some other function .it should give me tha data type and value of calling function parameter komal C++ 6 01-25-2005 11:13 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57