博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Microsoft AJAX Library Cheat Sheet(6):String和Object类型的扩展
阅读量:5057 次
发布时间:2019-06-12

本文共 3443 字,大约阅读时间需要 11 分钟。

本文为翻译,英文原版的Cheat Sheet(PDF版本)在此下载:

原作版权声明:

Copyright (c) 2004-2006, Milan Negovan http://www.AspNetResources.comAll rights reserved.Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:    * Redistributions of source code must retain the above copyright       notice, this list of conditions and the following disclaimer.          * Redistributions in binary form must reproduce the above copyright       notice, this list of conditions and the following disclaimer in       the documentation and/or other materials provided with the       distribution.          * The name of the author may not be used to endorse or promote products      derived from this software without specific prior written permission.THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

 

注:标注有[S]的为静态方法,无须实例化对象即可使用。

 

String.endsWith (suffix)

判断该String是否以指定的后缀结束。

var isTxt = myString.endsWith ("some_file.txt", ".txt");
// isTxt = true

 

[S] String.format (format, args)

将该String中的各个格式化项用相应的参数值替代。args可以为单一的Object,或是一个包含多个项的Array。

var user = {
FirstName: 'John',
LastName : 'Doe',
DOB: new Date (1975, 1, 17) };
var label = String.format ("User name: {0} {1}, born {2:d}",
user.FirstName, user.LastName, user.DOB));
// label = "User name: John Doe, born 02/17/1975"

 

[S] String.localeFormat (format, args)

功能与String.format (format, args)类似,不过格式化时与区域设定相关。

 

String.startsWith (prefix)

判断该String是否以指定的前缀开始。请参考String.endsWith (suffix)。

 

String.trim ()

返回一个原String的拷贝,但将原String开头和结尾部分的所有空白字符(例如空格或Tab)都移除。

var myString = "   A string   ";
myString = myString.trim();
// myString = "A string"

 

String.trimEnd ()

返回一个原String的拷贝,但将原String结尾部分的所有空白字符(例如空格或Tab)都移除。

var myString = "A string   ";
myString = myString.trim();
// myString = "A string"

 

String.trimStart ()

返回一个原String的拷贝,但将原String开头部分的所有空白字符(例如空格或Tab)都移除。

var myString = "   A string";
myString = myString.trim();
// myString = "A string"

 

[S] Object.getType (instance)

返回指定对象的类型,请参考Object.getTypeName (instance)。

 

[S] Object.getTypeName (instance)

返回一个表示对象在运行时的完全限定类型的字符串。

Type.registerNamespace("Samples");
// Define and register a Samples.Rectangle class.
Samples.Rectangle = function(width, height) {
this._width = width;
this._height = height;
}
Samples.Rectangle.registerClass("Samples.Rectangle");
var a = new Samples.Rectangle(200, 100);
var name = Object.getTypeName(a);
var type = Object.getType (a);
Sys.Debug.trace ("The type name of object \"a\" is: " + name);
Sys.Debug.traceDump (type);
/* The result is:
The type name of object "a" is: Samples.Rectangle
traceDump {Function}
prototype {Samples.Rectangle}
__typeName: Samples.Rectangle
__class: true
*/

转载于:https://www.cnblogs.com/dflying/archive/2007/02/09/646455.html

你可能感兴趣的文章
Codeforces 620E(线段树+dfs序+状态压缩)
查看>>
Windows7中双击py文件运行程序
查看>>
Market entry case
查看>>
bzoj1230 开关灯 线段树
查看>>
LinearLayout
查看>>
学习python:day1
查看>>
css3动画属性
查看>>
第九次团队作业-测试报告与用户使用手册
查看>>
Equal Sides Of An Array
查看>>
CentOS笔记-用户和用户组管理
查看>>
Mongodb 基本命令
查看>>
Qt中QTableView中加入Check列实现
查看>>
“富豪相亲大会”究竟迷失了什么?
查看>>
控制文件的备份与恢复
查看>>
返回代码hdu 2054 A==B?
查看>>
Flink独立集群1
查看>>
iOS 8 地图
查看>>
20165235 第八周课下补做
查看>>
[leetcode] 1. Two Sum
查看>>
iOS 日常工作之常用宏定义大全
查看>>