aardio 官方社区

 找回密码
 注册会员

QQ登录

只需一步,快速开始

搜索
查看: 8875|回复: 2

标准库里的string库 什么作用

[复制链接]

37

主题

146

回帖

1240

积分

四级会员

积分
1240
发表于 2012-3-11 21:06:16 | 显示全部楼层 |阅读模式
看帮助说 string是核心库,不用import ,
但是今天看标准库中也有一个string库,不知标准库中的那段简短的代码起到一个什么作用。

//string 字符串对象
namespace string;  

class string{
   
ctor( str,... ){
        
if(...)
            
return str,...;
            
        
this.str = tostring(str);
    };
    @meta
}

var prototype = {}
string.meta = {
    _get = prototype;
    _tostring =
function(){
        
return owner.str;
    }  
}
prototype.
tostring =  string.meta._tostring;

for(k,func in ..string){
     prototype[k] =
function(...){
        
return string( func(owner.str,...) )
     }
}

27

主题

646

回帖

4138

积分

超级版主

积分
4138
发表于 2012-3-11 21:23:18 | 显示全部楼层
这是 string.string 而不是内核库里的 string,

import string.string;
var str = string.string( "abcd123" )

import console
console.log(
    str.left(3)
// 等价于调用 string.left("abcd123" ,3 )
)

37

主题

146

回帖

1240

积分

四级会员

积分
1240
 楼主| 发表于 2012-3-12 09:03:30 | 显示全部楼层
quicker 发表于 2012-3-11 21:23
这是 string.string 而不是内核库里的 string,

import string.string;

是把内核库的string转成对象的用法的string吗
您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

手机版|未经许可严禁引用或转载本站文章|aardio.com|aardio 官方社区 ( 皖ICP备09012014号 )

GMT+8, 2025-12-13 06:28 , Processed in 0.060701 second(s), 22 queries .

Powered by Discuz! X3.5

Copyright © 2001-2024 Tencent Cloud.

快速回复 返回顶部 返回列表