please tell me how to create the property Getter and Setter ?
please tell me how to create the property Getter and Setter ?
I believe it is as follows:
As text:
var Getter="";
var Setter="";
As numerical:
var Getter=0;
var Setter=0;
Although I have been known to be wrong.
cr3ative
A retired member, drop me a line through my site if you'd like to find me!
cr3ative media | read the stickies
Care to be a little more specific? The word 'property' refers to a member of an object, so where is this object and how is it defined? If you're actually referring to variables, then cr3ative has just demonstrated that.Originally Posted by svincoll4
Mike
mwinter right, i want to create a property which refers to a member of an object, it's not variables. Thanks cr3ative.
Last edited by svincoll4; 06-23-2005 at 02:24 AM.
Yeah, I'm confused too. Rather than explaining it in such general terms. Tell us exactly what you want to do and what you want to do it to. Be specific, show us some coding attempts and explain what you wanted to have happen that didn't. For some reason this thread is reminding me of the getAttribute('attribute_name') and setAttribute('attribute_name','attribute_value') methods. Am I even warm?
- John________________________
Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate
sorry all, i say English not good.
i have an object: o_user. I want to create an property such then:
o_user.u_bgcolor='color' ;
then, the background color of document will changed.
Accept all ideas. Please help.
Last edited by svincoll4; 06-25-2005 at 01:06 AM.
We need more than that. How did the object get the name o_user? Is it the id of an element? Is it a variable that was assigned when an element was created? In order to really understand, it would be good if you:
PLEASE: Include the URL to your problematic webpage that you want help with.
- John________________________
Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate
I guess you want to apply OOP
yourfunc.prototype.getYourVar() {
return this.yourVar;
}
yourfunc.prototype.setYourVar(val) {
this.yourVar = val;
}
done
Without making assumptions as to what o_user is, I'd have to say that's not possible.Originally Posted by svincoll4
Host objects and their properties do often cause changes within the document, but that's because they are special and the browser can monitor them. However, native objects (ones that you create yourself) cannot be watched. You would have to use functions:
If o_user is a host object (such as a reference to a HTML element), then as John said we need more information. Preferably an example of what you've tried, and failed, to do.Code:o_user.setBackground = function(colour) { var body = document.body, style; if(body && (style = body.style)) { style.backgroundColor = colour; } };
That would just be a syntax error - a function call immediately followed by a block statement. You'd need to assign a function object to getYourVar similar to how I have above. However, in this simple example, there's no reason why one couldn't assign to the property directly.Originally Posted by dd2me
Mike
Does JavaScript support OOP?
If so, you can use:
This is how I would do it in Java. I have no idea if this would work with JavaScript.Code:class MyClass { private int green; public int getGreen() { return green; } public void setGreen(newgreen) { green = newgreen; } }
As a matter of interest, C# can actually integrate getters and setters into the variable itself, providing better control over variable access. I love this![]()
Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!
Bookmarks