Prev | Current Page 233 | Next

L. McColl-Sylvester and F. Ponticelli

"Professional haXe and Neko"

The getter method is also modified to use the newly defined
variable if it is different from null or recurring to the cropping functionality otherwise.
private var definedExcerpt : String;
public var excerpt(getExcerpt, setExcerpt) : String;
private function setExcerpt(value : String) : String
{
113
Chapter 5: Delving Into Object-Oriented Programming
definedExcerpt = value;
return definedExcerpt;
}
private function getExcerpt() : String
{
return if(definedExcerpt != null)
definedExcerpt;
else
content.substr(0, 10) + ??? ...???;
}
The excerpt property can now be set to a new value.
entry.excerpt = ???Blog Entry is easy???;
In traditional OOP, getter and setter methods are the preferred way to access variables, but in dynamic
languages such as JavaScript there is a general tendency to ignore this practice in favor of shorter,
easier - to - read code and faster execution; with properties definition you can always switch with ease from
instance variables to accessor methods.
The dynamic keyword in the context of variables is an advanced feature.


Pages:
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245