//方案一 () {
//單例方法
function Singleton(args) {
this.name = 'SingletonTester'; //方法對外的屬性,另一方法是回傳對象
this.pointX = args.pointX || 6;
>
//單例實例
var instance;
//返回物件
getInstance: function (args) {
== undefined) {
instance = new Singleton(args); }
};
)( 🎜>
//測試
var test = SingletonTester.getInstance({ pointX: 5 });
console.log(test.pointX);
console.log(test.pointX);
方案二: