codecamp

Scorpio 更清晰的变量作用域

                        //脚本里
			gameObject = 9;//第一层的
			t = {
				gameObject =10;//第二层的
				function k1(){
					gameObject;//这是第一层的,这需要注意
					this.gameObject;//这是自己第二层的
					t.gameObject;//这是自己第二层的
				}
			}
			//也就是说,表里要使用自己的,就需要用 this,不然会被当成最外的	
			
			//this是指向当前的表的,但有一种情况,this是失效的
			xx = {
				//这是找不到this的,因为是将函数赋予变量,而这个函数上面没有东西
				x1 = function(){}
				//这能找到,因为x2上面是xx表
				function x2(){}
			}


Scorpio 表、变量、函数、其作用域
Scorpio 宏定义
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }