typeScript 中的 private : 私有,只能被其定义所在的类访问。
runoob 教程给的demo
class Encapsulate {
str1:string = "hello"
private str2:string = "world"
}
var obj = new Encapsulate()
console.log(obj.str1) // 可访问
console.log(obj.str2) // 编译错误, str2 是私有的
运行把demo
虽然编译器提示,属性“str2”为私有属性,只能在类“Encapsulate”中访问。但是浏览器还是打印了私有属性