473,396 Members | 1,860 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,396 software developers and data experts.

How can I set an object's property read-only to public?

I have an object, that contains a status-property. The status gets set
by a function internal to that object. This function gets invoked as
/init();/ and sets the status-property of the outer function.

If I make that property world-readable via /this/ it will become
world-writable, too. Is there any way except of defining a getter
function to an inner property? I would like to get the property via
/Object.property/ still.

--
Bye,
Andreas M.
Jun 27 '08 #1
2 1084
On May 9, 9:02 am, "Andreas M." <foo...@invalid.invalidwrote:
I have an object, that contains a status-property. The status gets set
by a function internal to that object. This function gets invoked as
/init();/ and sets the status-property of the outer function.

If I make that property world-readable via /this/ it will become
world-writable, too. Is there any way except of defining a getter
function to an inner property? I would like to get the property via
/Object.property/ still.

--
Bye,
Andreas M.
Make it a private property and use a getter.

For example:

function myClass ()
{
this.public = 0; // This property is fully accessible from the
outside
var private = 1; // This property is inaccessible from outside the
object

this.getPrivate = function ()
{
return (private);
}
}

myObj = new myClass ();

alert (myObj.getPrivate ());
Jun 27 '08 #2
On May 9, 10:02*am, "Andreas M." <foo...@invalid.invalidwrote:
I have an object, that contains a status-property. The status gets set
by a function internal to that object. This function gets invoked as
/init();/ and sets the status-property of the outer function.

If I make that property world-readable via /this/ it will become
world-writable, too. Is there any way except of defining a getter
function to an inner property? I would like to get the property via
/Object.property/ still.
No. There isn't.
Any (non-native) Object.property is writable as long as it's visible.
Reducing the visibility of the status-property (hiding it into a
closure) would protect it, but its getter() would still be r/w anyway,
it could be hijacked to return something != status-property. Viva the
mutability.

--Jorge.
Jun 27 '08 #3

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

Similar topics

4
by: Ralph?? | last post by:
I'm trying to use object pointers to access/modify various properties of various layers. The problem i'm having is that pointers created within my functions dont have world scope even though the...
3
by: Steve | last post by:
Guys, I've written a custom control (or at least tweaked someone else's!) in C# to be used on forms (rather than asp.net forms). The control is a date time picker, but its Value property returns...
6
by: Luke | last post by:
Here is my emails to Danny Goodman (but probably he is very busy so he didn't answered it). First email(simple): Subject: JavaScript Arrays " We all know the array can act like HashMap, but is...
2
by: Alex | last post by:
I have a property: Protected Overrides ReadOnly Property ListItemType() As Object Get Return GetType(myObject) End Get End Property How could i create a new object of the type 'myObject'...
7
by: Martin Robins | last post by:
I am currently looking to be able to read information from Active Directory into a data warehouse using a C# solution. I have been able to access the active directory, and I have been able to return...
5
by: hamerb | last post by:
So the line of code I'm working on is something like this: func(ref obj.GetType().GetProperty(PopertyNameSring).GetValue(obj, null)) This ofcourse doesn't work since the GetValue method gets...
9
by: Jim in Arizona | last post by:
I get this error: Unable to cast object of type 'System.Web.UI.HtmlControls.HtmlInputText' to type 'System.Web.UI.WebControls.TextBox'. Using this code: Dim test3 As TextBox test3 =...
4
by: jm.suresh | last post by:
Hi, Is there any standard text format for storing data of object oriented nature. The text file should be readable. That is, Is there any better way than having to write out a file like this...
28
by: Stef Mientki | last post by:
hello, I'm trying to build a simple functional simulator for JAL (a Pascal-like language for PICs). My first action is to translate the JAL code into Python code. The reason for this approach is...
0
by: =?Utf-8?B?RmFicml6aW8gQ2lwcmlhbmk=?= | last post by:
I need to access classic ASP intrinsic objects and their properties from a ..net assembly wrapped to COM. The COM .net assembly is then instanciated from a classic ASP page with...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: 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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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,...

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.