codecamp

Scorpio 函数

//普遍函数
			//function 函数的名称( 参数们 ){ 内容 }
			function text1( a ){
				//可以有的返回值,值类型随意,注意该返回值不能返回多值,但能返回 脚本数组之类的制造多值,
				//例如 return a = [6,7,8]; 	这样新建一个脚本数组 值返回的
				return "a";
			}

		
			//参数不需要填写类型
			function text1( a ){
				//函数内加入 固定变量,以让外部可访问,这是很不推荐的
				t = "xx";
			}

			
			//不固定参函数
			//a c d 都是普通参数来的
			//...b 是不固定参数,类型是 脚本数组,
			//注意 不固定参数 必须在最后定义,否则会出错,可以只定义不固定参数,不定义普通参数 例如 function text1( ...a ){}
			function text1( a , c , d , ...b ){
				//这是普通参数
				a + c + d;
				//遍历不固定参数 b ,它是脚本数组类型,脚本数组的具体使用,看最上面的导航 “array库”
				foreach( pair in pairs( b )){
					//该数组里的变量 是顺序的
					pair.value;
				}
			}
			
			
			//函数也可以给变量的
			var f = text1;
			f( 9 ); 

			
			//函数不可用多态的,只能有一条
				function x( a , b , c ){}
				function x(){};
				//这会导致执行不对正确的函数			
	
	
			//函数内可以嵌套函数等的
				function test(data) { 
					return function() {
						print(data)
					}
				}
				var b = test(100)
				b()
				test(200)
				b()		
	

	
			//函数可以在外部定义内部变量的值,但不推荐使用
				function test() { print(str) }
				test.str = "hello world"
				
				test = function() { print(str) }
				test.str = "hello world"
	


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; }