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

更新时间:2023-07-14 13:04:02 阅读: 评论:0

ree
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)
);
}
};
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 cond variable being tested against
* @param {*} test1 The value to test
* @param {*} test2 The value to test against
ours
* @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
);
}
};
写完发现,看变量名也能看懂啥意思...⽔了⽔了...

本文发布于:2023-07-14 13:04:02,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/90/177167.html

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

标签:类型   判断   函数
相关文章
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图