function Test(){
var name = 'test'//私有
this.age = 12//公有
this.getName = function(){
return name
}
this.getAge = function(){
return this.age
}
}
var Test = new Test()
print(Test.name)//undefined
print(Test.age)//12
print(Test.getAge())//12
print(Test.getName())//'test'
模块模式
var singleton = function(){
//私有变量和函数
var privateVariable = 10
function privateFunction(){
return false
}
//创建对象
var object = new CustomType()
object.publicProperty = true;
object.publicMethod = function(){
privateVariable++
return privateFunction()
}
return object;
//特权/公有方法和属性
// return {
// publicProperty:true,
// publicMethod:function(){
// privateVariable++
// return privateFunction()
// }
// }
}()
//单例接口
var application = function(){
//私有
var components = new Array()
components.push(new BaseComponent())//BaseComponent()作为初始化操作
var app = new BaseComponent()
app.getComponentCount = function(){
return components.length
}
app.registerComponent = function(component){
if(typeof component == "object"){
components.push(component)
}
}
return app
// return {
// getComponentCount:function(){//返回已注册的组件数
// return components.length
// },
// registerComponent:function(component){//注册新组件
// if(typeof component == "object"){
// components.push(component)
// }
// }
// }
}
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有