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