带构造函数

类型初始化 / 结构体

# 结构体:由函数构建的命名列表
new_size <- function(width, height) {
  list(width = width, height = height)
}

new_point <- function(top, left) {
  list(top = top, left = left)
}

new_rectangle <- function(size, point) {
  list(size = size, point = point)
}

size <- new_size(10, 10)
# 按名称传递参数
point <- new_point(top = 5, left = 5)
rect <- new_rectangle(size, point)

str(rect)