I'm going through the following S3-Tutorial: http://www.cyclismo.org/tutorial/R/s3Classes.html
I like the "Local Environment Approach" (and can live with its disadvantages). But I d'ont understand why there is the manual creation of a local environment. Why don't we just use the functions environment?
The following seems to workeven without the "extra" environment:
Person <- function(name) {
name <- name
me <- list(
getName = function() {
return(name)
}
)
class(me) <- append(class(me), "Person")
return(me)
}
jan <- Person("Jan")
max <- Person("Max")
jan$getName()
max$getName()
What am I missing here?