码迷,mamicode.com
首页 > Web开发 > 详细

js - 常用功能方法汇总(updating...)

时间:2018-10-30 21:22:22      阅读:167      评论:0      收藏:0      [点我收藏+]

标签:auth   eof   def   方法   常用   put   updating   author   @param   

一、查值的类型(可用于拷贝)

 1 /*
 2     * @Author: guojufeng@ 
 3     * @Date: 2017-12-20 15:07:06
 4     * @purpose 获取一个值的类型
 5     * @param {variateName} target: 要获取类型的变量名或对象
 6     * @output {string} result || "null": 返回的参数 - result或者null,为字符串形式的
 7     */
 8     function getType(target) {
 9       if(target === null){
10         console.log(target)
11         return "null";
12       }
13       let result = typeof (target);
14       if (result == "object") { 
15         if (target instanceof Array) {
16           result = "array";
17         } else if (target instanceof Object) {
18           result = "object";
19         }
20       }
21       console.log(result)
22       return result;//返回类型值的字符串形式
23     }

 应用:

1 var nu= null;// null 怎么算
2 var un= undefined;
3 var c = new Array;
4 var d = {};
5 console.log(getType(c),getType(d),getType(nu),getType(un))

 

js - 常用功能方法汇总(updating...)

标签:auth   eof   def   方法   常用   put   updating   author   @param   

原文地址:https://www.cnblogs.com/padding1015/p/9879219.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!