码迷,mamicode.com
首页 > 编程语言 > 详细

javascript中字符串的两种定义形式

时间:2014-11-03 01:15:17      阅读:214      评论:0      收藏:0      [点我收藏+]

标签:ar   java   sp   bs   new   as   javascript   nbsp   字符串   

1、var s = "this is a string";

   var t = "this is also a string";

  s.test = 20;

2、var s = new String("this is a string");

     var t = new String("this is also a string");

   s.test = 20;

这两种方式有何区别?

第一种方式定义的test为s、t以及将来的所用此种形式定义的字符串定义了test.

第二种方式定义的test仅为s定义.

javascript中字符串的两种定义形式

标签:ar   java   sp   bs   new   as   javascript   nbsp   字符串   

原文地址:http://www.cnblogs.com/fantasy01/p/4070330.html

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