Pot*_*Ion 1 javascript variables object
我已经看到变量的实例既是对象又是字符串.例:
alert(x + ""); // Hello
alert(x()); // World
Run Code Online (Sandbox Code Playgroud)
这种事情是jQuery对$变量的作用.
你怎么会得到这种效果?
不,变量既不能是对象,也不能是(原始)字符串.
但是,如果您尝试将对象转换为字符串(例如,使用obj + ''),toString则使用其方法返回的字符串.
function x() {
return "World";
}
x.toString = function() {
return "Hello";
};
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
89 次 |
| 最近记录: |