javascript typeof应用
typeof 是JavaScript的运算符
——返回一个用来表示表达式的数据类型的字符串
typeof[(] expression [)] //typeof语法中的圆括号是可选项
typeof 运算符@import url(../html-vss/msdnie4a.css);
typeof
运算符把类型信息当作字符串返回。typeof
返回值有六种可能: "number," "string,"
"boolean," "object," "function," 和 "undefined."
实例<html>
<head>
<title>typeof测试用例页面</title>
<mce:script type="text/javascript"><!--
t = function(i) {
alert(typeof 123);//number
alert(typeof("123"));//String
}
// --></mce:script>
<mce:style type="text/css"><!--
div {
opacity: 0.5;
}
--></mce:style><style type="text/css" mce_bogus="1"> div {
opacity: 0.5;
}
</style>
</head>
<body>
<div onclick="t(1)">测试typeof</div>
</body>
</html>
相关文档:
1.浮点运算
这可能是挫败一些对javascript不熟悉并准备执行一些数学运算的人的主要原
因.
<script>
alert(0.02 / 0.1); //0.19999999999999998
alert(1.14 * 100); //113.99999999999999 ;)
......
第三章 DOM Scripting DOM编程
DOM scripting is expensive, and it's a common performance bottleneck in rich web applications. This chapter discusses the areas of DOM scripting that can have a negative effect on an application's responsiveness and gives recommendations o ......
var
xmlDoc
=
null
;
function
parseXML
(
xmlUrl
)
{
try
{
//IE
xmlDoc
=
new
ActiveXObject
(
"Microsoft.XMLDOM"
);
xmlDoc
.
async
=
false
;
xmlDoc
......
2、原型方式写类,原型方式继承
core js自身的对象系统就是采用原型方式(prototype based)继承的。或者说core
js没有采用常见的类继承(class
based)系统,而是使用原型继承来实现自己的对象系统。工作中我们也可以用原型方式来实现继承,代码复用以构建自己的功能模块。
/**
* 父类Polygon:多边形
*
*/
functio ......
Closure中文翻译为闭包.字面上来理解就是"封闭的包".(这是一句废话)
闭包是什么?
书面解释为:
所谓“闭包”,指的是一个拥有许多变量和绑定了这些变量的环境的表达式(通常是一个函数),因而这些变量也是该表达式的一部分。
我认为闭包就是能够读/写函数内部的某些变量的子函数,并将这些变量保存 ......