DIGG IT!
0
Comments
Published
Thursday, March 11, 2004
at
11:13 AM
.
One of the problems with getter/setters in Flash is that you must find a location to store the protected property and all to often that area is not that protected. Often this leads to property pollution as there are now 2 variables, the getter/setter and the protected property it gets and sets. Not good.
//define function for both getter and setter
f = function(s){
//reference to the executing function object
var self = arguments.callee
//getter
if(arguments.length <1){
//return the value
return self.privateProp
//setter
}else{
//set the value
self.privateProp = s
}
}
addProperty('publicProp',f,f)
//delete the local reference to make the property truely private and inaccessable
delete f
//set the property
publicProp = 23
//get the property
trace(publicProp)
Ted on Twitter - @AdobeTed
Ted on Adobe Groups
Ted on LinkedIn
Ted on Facebook
Ted at Adobe
0 Responses to “Truly Private Getter/Setters”
Post a Comment