defining classes-- different methods

M

Matt Kruse

VK said:
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.
 
B

Bart Van der Donck

VK said:
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-5.8.8/pod/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.
 
V

VK

Matt said:
"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.
 
J

John G Harris

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
 
V

VK

The sigil itself in "tentatively private member" name is for more easy
I haven't the slightest idea what POD has to do with this.
http://search.cpan.org/~nwclark/perl-5.8.8/pod/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.
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.
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".
 
B

Bart Van der Donck

VK said:
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 :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top