jh****@gmail.com wrote:
Hi all
I'm lookup for a documentation or explanation abour the visibility and
syntax about class.
I found the ECMAScript Language Spec. 3 (final) & 4 (draft) but it's
not very easy to read this doc...
I wish create a simple class with a constructor and a method using the
keyword 'this' but i've strange error.
sample of code tried...
===============================
function class1(arg...) {
Cleaning up the syntax...
function class1(arg) {
That creates a function object with a local variable, arg.
this.arg = arg ;
The value of the 'this' operator depends on how you call the function.
If you just call it as class1(), then its this operator will be the
global object.
When 'class1' is called as a constructor with the new operator, its this
operator will be a reference to the newly created object. 'this.arg'
will create a public property of the new object called 'arg'. The line
above assigns the value of class1's local 'arg' variable to the new
object's arg property:
// Declare the constructor function
function class1(arg){
this.arg = arg;
}
// Use it with 'new' to create a new object and assign a value to
// its arg property
var x = new class1('foo');
// Show its value
alert(x.arg); // Shows 'foo'
[...]
>
TEST1 :
i try :
// don't works
function getarg(){
return this.arg ;
}
This creates a function getarg() in a global scope. If you call it:
getarg();
its this operator will refer to the global object (window object in a
browser), so it will return the value of the arg property of the
global/window object (which hasn't been defined anywhere here and so is
undefined).
TEST2 :
function C(){
function class1(arg...) {
This will create class1() as a private method of the C function object.
You can't call it from outside C.
this.arg = arg ;
...
}
}
to access to arg i tried
return C:arg ; // don't works
That is a straight syntax error.
return C.arg ; // don't works
That won't work because arg is not a public property of the function
object referenced by C.
how can I do that
See above.
--
Rob