cesium源代码之类型判断:check.js文件

cesium源代码之类型判断:check.js⽂件
cesium源代码之类型判断:check.js⽂件
利⽤cesium⼆次开发的时候,本来以为还要⾃⼰写参数类型判断的代码,后来发现cesium⾥已经写好了,直接new peOf.调⽤就可以了。
源代码在source/core/cheak.js⽂件中,接下来来看看⾥⾯的源代码:
1.⽂件开头
引⼊两个模块,第⼀个是定义默认值的,第⼆个是报异常的⽂件。
import defined from"./defined.js";
import DeveloperError from"./DeveloperError.js";
2. 定义全局对象和异常提⽰函数
peOf是全局对象,下⾯得函数是类型错误报错函数。
var Check ={};
/**
* Contains type checking functions, all using the typeof operator
*/
function getUndefinedErrorMessage(name){
return name +" is required, actual value was undefined";
}
function getFailedTypeErrorMessage(actual, expected, name){
return(
"Expected "+
name +
" to be typeof "+
expected +
", actual typeof was "+
actual
);
}
3. 类型判断
判断函数、字符串、数字、布尔、对象类型。
if(typeof test !=="function"){
throw new DeveloperError(
getFailedTypeErrorMessage(typeof test,"function", name)
);
}
};
if(typeof test !=="string"){
throw new DeveloperError(
getFailedTypeErrorMessage(typeof test,"string", name)
);
}
};
if(typeof test !=="number"){
throw new DeveloperError(
getFailedTypeErrorMessage(typeof test,"number", name)
);
}
};
2008奥运会会徽
if(typeof test !=="boolean"){
throw new DeveloperError(
getFailedTypeErrorMessage(typeof test,"boolean", name)
)
;
}
};
if(typeof test !=="object"){
throw new DeveloperError(
getFailedTypeErrorMessage(typeof test,"object", name)
);王承绪
}
};
4. ⼤⼩判断
判断数字与传⼊的数字只见的⼤⼩,有⼩于、⼩于等于、⼤于、⼤于等于、等于。
if(test >= limit){
throw new DeveloperError(
"Expected "+
name +
" to be less than "+
limit +
", actual value was "+
test
)
;
}
};
/**
* Throws if test is not typeof 'number' and less than or equal to limit
*
* @param {String} name The name of the variable being tested
* @param {*} test The value to test
* @param {Number} limit The limit value to compare against
* @exception {DeveloperError} test must be typeof 'number' and less than or equal to limit  */
*/
if(test > limit){
throw new DeveloperError(
"Expected "+
name +
" to be less than or equal to "+
limit +
", actual value was "+
test
);
}
};
/**
* Throws if test is not typeof 'number' and greater than limit
*
* @param {String} name The name of the variable being tested
* @param {*} test The value to test
* @param {Number} limit The limit value to compare against
* @exception {DeveloperError} test must be typeof 'number' and greater than limit
*/
if(test <= limit){
throw new DeveloperError(
"Expected "+
name +
" to be greater than "+
limit +
", actual value was "+
test
);
}
};
/**
* Throws if test is not typeof 'number' and greater than or equal to limit
*
* @param {String} name The name of the variable being tested
* @param {*} test The value to test
* @param {Number} limit The limit value to compare against
* @exception {DeveloperError} test must be typeof 'number' and greater than or equal to limit  */
if(test < limit){
throw new DeveloperError(
"Expected "+
受益人评价
name +
" to be greater than or equal to"+
limit +
", actual value was "+
test
);
}
};
/**
* Throws if test1 and test2 is not typeof 'number' and not equal in value
*穿红裙子的语文老师
* @param {String} name1 The name of the first variable being tested
* @param {String} name2 The name of the second variable being tested against
* @param {*} test1 The value to test
* @param {*} test2 The value to test against
* @exception {DeveloperError} test1 and test2 should be type of 'number' and be equal in value  */
须鳗虾虎鱼
if(test1 !== test2){
throw new DeveloperError(
name1 +
" must be equal to "+
name2 +
光棍儿电影下载", the actual values are "+
test1 +
" and "+
test2
);
}
};
写完发现,看变量名也能看懂啥意思...⽔了⽔了...

本文发布于:2024-09-26 00:32:01,感谢您对本站的认可!

本文链接:https://www.17tex.com/xueshu/212456.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:类型   判断   函数   对象   数字   源代码   语文   电影
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2024 Comsenz Inc.Powered by © 易纺专利技术学习网 豫ICP备2022007602号 豫公网安备41160202000603 站长QQ:729038198 关于我们 投诉建议