Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > defining classes-- different methods

Reply
Thread Tools

defining classes-- different methods

 
 
Matt Kruse
Guest
Posts: n/a
 
      11-28-2006
VK wrote:
> Well, if you are serious in what you are saying then your perception
> of JavaScript and especially its inheritance is seriously damaged.


Your bickering is quite unproductive. And you are clearly wrong.

> function C() { ; }
> C.prototype.n = 5;
> var obj = new C;
> alert(obj.n); // 5


"Static" properties do not belong to an instance of a class, they belong to
the class itself.
In java, if a class has a static property and you access it as a property of
an instance, the compiler should throw a warning.

In the example above, how would you access the value of n without creating
an instance of C?

The answer is, you can't (other than looking at the prototype directly).
Accessing C.n will not work. If you have to create an instance of a class to
access a "static" property, then it's not a static property.

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com


 
Reply With Quote
 
 
 
 
Bart Van der Donck
Guest
Posts: n/a
 
      11-28-2006
VK wrote:

> The sigil itself in "tentatively private member" name is for more easy
> "visual" code navigation between the team members plus for automated
> POD generation


I haven't the slightest idea what POD has to do with this.
http://search.cpan.org/~nwclark/perl...od/perlpod.pod

> (Hungarian notation would be way too "heavy" for JavaScript).


I don't see why that couldn't be a valid personal preference for a
coder. You seem to suggest that it isn't too "heavy" then in other
languages ?

> "$" for sigil instead of say underscore is a personal preference (a
> subconscious Perl influence maybe


An underscore can never act as a sigil; underscores are part of the
variable's name.

--
Bart

 
Reply With Quote
 
 
 
 
VK
Guest
Posts: n/a
 
      11-28-2006

Matt Kruse wrote:
> "Static" properties do not belong to an instance of a class, they belong to
> the class itself.


There is a single field/property/method instance "belonging" to class
but referenced in each class instance.

> In java, if a class has a static property and you access it as a property of
> an instance, the compiler should throw a warning.


>From what sky blue? Of course not (unless you have some paranoidal

compiler). But if I change static property over instance it will be
still "reflected" in all other instances as well.

> In the example above, how would you access the value of n without creating
> an instance of C?
> The answer is, you can't (other than looking at the prototype directly).
> Accessing C.n will not work. If you have to create an instance of a class to
> access a "static" property, then it's not a static property.


How the h & f would anyone create "an instance of a class" without
having a class?
function C() {} in JavaScript
is not
public class C(){} in Java
and how the h & f would anyone talk about hardcoded inheritance in
JavaScript without prototype?

The turkey this year was really good and I don't want to spoil the rest
of my mood. Let's say that there is "js_static" methods where a single
method instance is shared by reference among all object instances (as
strictly opposed to real "static" method in say Java where a single
method instance shared by reference among all class instances).
Obviously only VK can take "js_static" for "static" when the difference
is so obvious.

I keep my freedom to call them static though, you may call it however
you want or just leave anonymous.

 
Reply With Quote
 
John G Harris
Guest
Posts: n/a
 
      11-28-2006
In article <(E-Mail Removed) .com>, VK
<(E-Mail Removed)> writes

<snip>
>the second one leads to the non-sense like
>"Array is Object, just with that funny length property added"


No-one is saying that.


>(Array is
>an object by it is not the Object: but it inherits from and extends

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>base Object constructor).

^^^^^^^^^^^^^^^^^^^^^^^
<snip>

That is not true.


John
--
John Harris
 
Reply With Quote
 
VK
Guest
Posts: n/a
 
      11-28-2006
> > The sigil itself in "tentatively private member" name is for more easy
> > "visual" code navigation between the team members plus for automated
> > POD generation

>
> I haven't the slightest idea what POD has to do with this.
> http://search.cpan.org/~nwclark/perl...od/perlpod.pod


Sorry, just slangish from my side. I meant (Perl in mind) automatically
generated help source out of information "encoded" in the program
source itself.

> > (Hungarian notation would be way too "heavy" for JavaScript).

>
> I don't see why that couldn't be a valid personal preference for a
> coder. You seem to suggest that it isn't too "heavy" then in other
> languages ?


It is not in strictly typed languages with pointers and stuff. In
JavaScript a good half of the system would left unused. At the same
time absolutely nothing prevents of using the Hungarian notation in
JavaScript: anyone is welcome. That was nothing but my (our) particular
choice and I just provided the main reason of it.

> > "$" for sigil instead of say underscore is a personal preference (a
> > subconscious Perl influence maybe

>
> An underscore can never act as a sigil; underscores are part of the
> variable's name.


Obviously we are talking "sigils" in the abstract way as some repeating
part of the identifier at the beginning: because JavaScript doesn't
have type modifiers ("sigils") as such. Whatever sign (or combination
of signs) it will it is always a part of the name (just like in
Hungarian notation). In this aspect "$" is no different from "_" or say
"prv".

 
Reply With Quote
 
Bart Van der Donck
Guest
Posts: n/a
 
      11-29-2006
VK wrote:

> Obviously we are talking "sigils" in the abstract way as some repeating
> part of the identifier at the beginning: because JavaScript doesn't
> have type modifiers ("sigils") as such.


A sigil is not a modifier but a character that indicates the type of
the variable. It doesn't modify anything.

> Whatever sign (or combination of signs) it will it is always a part of the
> name (just like in Hungarian notation).


Sigils are certainly no part of the name. Say array @cars contains
('Audi', 'Opel', 'Toyota'), then $cars[0] could be 'Audi' and $#cars
the number of elements in the array (two).

The sigils here are @, $ and $# (the last one is actually a twigil).
But the variable's name is 'cars'; sigils are only *added* to a
variable. If you would say '@array_cars', then 'array_' is the
Hungarian part and '@' the sigil.

> In this aspect "$" is no different from "_" or say "prv".


Yes, the discussion is irrelevant because no such things as sigils
exist in javascript. What you did is actually use $ as a Hungarian
notation, not as a sigil

--
Bart

 
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
Is there a way to find the class methods of a class, just like'methods' finds the instance methods? Kenneth McDonald Ruby 5 09-26-2008 03:09 PM
Win32::OLE different connections methods produce different results HmJ Perl Misc 0 03-28-2008 02:46 PM
Defining methods outside of script tags Jasper Pearlman ASP .Net 3 08-16-2004 12:26 PM
defining or not defining destructors johny smith C++ 8 07-02-2004 08:51 AM
Coding Style: Defining Functions within Methods? Harry Pehkonen Python 8 09-08-2003 01:46 PM



Advertisments