如下代码:
<script>
var strObject = String( "I am a string" );
console.log(strObject); // I am a string
console.log(typeof strObject); // string
console.log(strObject instanceof String); // false
strObject = new String( "I am a string" );
console.log(strObject); // String {"I am a string"}
console.log(typeof strObject); // object
console.log(strObject instanceof String); // true
</script>
另外请问,String()函数内部,究竟干了什么事?
http://www.w3school.com.cn/jsref/jsref_obj_string.asp
一个返回对象,一个返回字符串
String() 是函数,返回字符串;和 new 使用时 String 是构造函数,返回字符串对象。
本人最近建立了开源项目usuallyjs,非常欢迎楼主一起交流,github地址:https://github.com/JofunLiang/usuallyjs,别忘了start哦.