JS作用域及call

<script type="text/javascript">
	function log(val){
		console.log(val);
	}

	function base(){
		this.name = 'base';
		this.write = function(){
			log('write => ' + this.name);
		}
	}

	var bt = function(){};
	bt._instance = null;
	
	bt.getInstance = function(){
		log(this._instance)
		if(this._instance == null){
			this._instance = new this();
		}
		return this._instance;
	};

	bt.prototype.go = function(){ //prototype
		log('go');
	};

	bt.prototype.init = function(){
		base.call(this);

		this.name = 'bt';
		this.write();
		this.go();
	}

	 bt.getInstance().init();
	 

	// function test(){
	// 	var i = 100;
	// 	this.go = function(){
	// 		alert('test go');
	// 	};
	// };

	// function base(){
	// 	this._instance = null,
	// 	this.write = function(){
	// 		log('write');
	// 	},
	// 	this.go = function(){
	// 		log('go');
	// 	}

	// 	var ts = function(){
	// 		alert('ts');
	// 	}

	// 	void function(){
	// 		log(_instance)
	// 	}();
	// };
	// base.getInstance = function(){
	// 	log('getInstance');
	// }

	// // var _base = new base();
	// // log(_base._instance);
	// // base.getInstance();
	// base();





	
</script>

  

posted @ 2016-08-25 13:40  sp5i5s  阅读(241)  评论(0)    收藏  举报