473,794 Members | 2,729 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1753
jh****@gmail.co m 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.prototyp e.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.co m 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.pro totype.pBar = function(contai ner,theme,min,m ax,step){

if (container==nul l)
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.pro totype.init_pBa r = 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.co m wrote:
thx... but i don't understand why that won't works...

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

ProgressBar.pro totype.pBar = function(contai ner,theme,min,m ax,step){

if (container==nul l)
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.pro totype.init_pBa r = 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.co m wrote:
RobG ; i see ur message after write my response... i try what u say ...

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

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

ProgressBar.pro totype.pBar = function(contai ner,theme,min,m ax,step){

if (container==nul l)
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.pro totype.init_pBa r = function() {
alert(this.min) ;
}

}

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

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

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

// Initialise the values of x's variables
x.pBar('contain er', '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
1882
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 src="RightPointingTriangle.gif" onclick="openclose(this);"> <span class="title">title</span> <div class="contents"> Hi. This is the contents.
4
1516
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 and i'm not sure how to make them appear underneath. I have a feeling it might be to do with the amount of space in my frames, as i have two frames, one 20% where the script is loading and another 80% for my main content, so the 20% is where my...
1
3256
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 of my link file that should load next to the menu on the same page. And Thank You in advance. Here is my menu applet: <html>
5
2104
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 need it too, except Safari 1.0.2 Here is the script. Please tell me if there is any more information I can give you.
3
1794
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 work when I add the scrolling text script. One script, the menu button script, has an "Onload" command and the other one does not. From what I know, and that's not much, I need to put both scripts in the "Onload" command. I just don't know how to...
2
4759
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 : ----------- <div id="index" style="position:absolute; width:200px; height:115px; z-index:1; left:-400px; top: 286px visibility:false;">
28
2605
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 paragraph. This will be on a web page. Thanks! --Randy Starkey
1
2164
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, I did not want to try to modify the code without a little help. When you place the mouse over the menu bar, this script calls the function to show the menu. I would like it modified to hide the menu when the mouse is removed. Please help. The...
3
3687
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 html is: <a class="searchsavechanges btn btn3d tbbtn" href="javascript:" style="position:static"> <div id="TBsearchsavechanges">Search</div> </a>
0
10433
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10212
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10000
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9035
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7538
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6777
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5436
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3720
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2919
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.