473,386 Members | 1,873 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

ECMS Script - Class and visibility

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...) {

this.arg = arg ;
....

}

===============================

how can i access to arg via an outside function.
TEST1 :
i try :
// don't works

function getarg(){
return this.arg ;
}

TEST2 :

function C(){

function class1(arg...) {

this.arg = arg ;
...

}
}

to access to arg i tried
return C:arg ; // don't works
return C.arg ; // don't works

how can I do that

thanks

regards.

Jacques. H

Aug 23 '06 #1
6 1738
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...) {

this.arg = arg ;
...

}

===============================

how can i access to arg via an outside function.
You can't. It's an instance variable only available to a class1
instance.
>

TEST1 :
i try :
// don't works

function getarg(){
return this.arg ;
}

What you should do is make getarg() a function of class1, then it can
see it:

class1.prototype.getarg() {
return this.arg;
}

>
TEST2 :

function C(){

function class1(arg...) {

this.arg = arg ;
...

}
}

to access to arg i tried
return C:arg ; // don't works
return C.arg ; // don't works

how can I do that
var C = new class1('testing');
alert(C.getarg()); //assumes you did what I recommended above
>
thanks

regards.

Jacques. H
HTH

Aug 23 '06 #2
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
Aug 23 '06 #3

thx... but i don't understand why that won't works...

Sample of Code :
==================================
// Progress Bar
function ProgressBar(){

ProgressBar.prototype.pBar = function(container,theme,min,max,step){

if (container==null)
this.container = container ;
if (theme==null)
this.theme = "default" ;
if (min==null)
this.min = min ;
if (max==null)
this.max = max ;
if (step==null)
this.step = step ;

}

ProgressBar.prototype.init_pBar = function() {
alert(this.min) ;
}

}

====================

alert return undefined !! why ?

Aug 23 '06 #4
RobG ; i see ur message after write my response... i try what u say ...

thanks .
jh****@gmail.com wrote:
thx... but i don't understand why that won't works...

Sample of Code :
==================================
// Progress Bar
function ProgressBar(){

ProgressBar.prototype.pBar = function(container,theme,min,max,step){

if (container==null)
this.container = container ;
if (theme==null)
this.theme = "default" ;
if (min==null)
this.min = min ;
if (max==null)
this.max = max ;
if (step==null)
this.step = step ;

}

ProgressBar.prototype.init_pBar = function() {
alert(this.min) ;
}

}

====================

alert return undefined !! why ?
Aug 23 '06 #5
I's OK that works !!

thanks for all

5* for your course. ;)
jh****@gmail.com wrote:
RobG ; i see ur message after write my response... i try what u say ...

thanks .
jh****@gmail.com wrote:
thx... but i don't understand why that won't works...

Sample of Code :
==================================
// Progress Bar
function ProgressBar(){

ProgressBar.prototype.pBar = function(container,theme,min,max,step){

if (container==null)
this.container = container ;
if (theme==null)
this.theme = "default" ;
if (min==null)
this.min = min ;
if (max==null)
this.max = max ;
if (step==null)
this.step = step ;

}

ProgressBar.prototype.init_pBar = function() {
alert(this.min) ;
}

}

====================

alert return undefined !! why ?
Aug 23 '06 #6
jh****@gmail.com wrote:
I's OK that works !!
Fixing your other attempt:

// Create an empty constructor
function ProgressBar(){}
// Give its prototype a 'pBar' method
ProgressBar.prototype.pBar = function(container,theme,min,max,step)
{
this.container = container;
this.theme = "default";
this.min = min;
this.max = max;
this.step = step;
}
// An an 'init_pBar' method
ProgressBar.prototype.init_pBar = function() {
alert(this.min) ;
}
// Create x as an instance of ProgressBar
var x = new ProgressBar();

// Initialise the values of x's variables
x.pBar('container', 'theme', 'min', 'max', 'step');

// Call x's init_pBar method
x.init_pBar();

--
Rob
Aug 23 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Rostov | last post by:
I've got a script where I'm trying to toggle the visibility of a div node by a click on an image that is the sibling of the div. So I've got this HTML: <div> <img...
4
by: natty | last post by:
I have been trying to edit a script for a drop down type menu. the script is working as the sub menus flash up when i hover over the title links, but they are appearing in the top left hand corner...
1
by: bayouprophet | last post by:
Cant get menu script to to put linked page in the same frame. I am new to Java and I am wondering what am I doing wrong? below are my java applet file, frame.html file, and my text file and one...
5
by: Kim Forbes | last post by:
Hi, I realize my first problem is that I'm using browser detection and not feature detection. Maybe someone can help me understand feature detection. This script works in every browser that I...
3
by: P Wolpert | last post by:
This is my first post. I hope I don't sound stupid. I have a script conflict when I put two scripts on one page. Both scripts will work if I use one at a time but the menu button script will not...
2
by: Nasir Wasim | last post by:
How can Access DIV Properties in Script while using Netscape 7.2. I want to use the div id with it's Visibility and left propertyin script but it's not working :-( Main File : ----------- ...
28
by: Randy Starkey | last post by:
Hi, Does anyone know where I can get a script that show a little plus sign after a line of text, that when you click the plus sign, more text is revealed on that same page, like a continuing...
1
by: Anthony | last post by:
Below is a script I found at http://javascript.internet.com/ for a cascading menu. The script works great but there is one thing that I would like modified. BecauseI am just learning javascript,...
3
by: Angus | last post by:
I have a web page with a toolbar containing a Save button. The Save button can change contextually to be a Search button in some cases. Hence the button name searchsavechanges. The snippet of...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.