prototype中的$H函数的用法
将对象转为hash对象
Creates a Hash
(which is synonymous to "map" or "associative array" for our purposes). A convenience wrapper around the Hash
constructor, with a safeguard that lets you pass an existing Hash
object and get it back untouched (instead of uselessly cloning it).
The $H
function is the shorter way to obtain a hash (prior to 1.5 final, it was the only proper way of getting one).
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <title>$H</title>
- <script type="text/javascript" language="javascript"
- src="prototype.js" ></script>
- <script>
- function test()
- {
- // 创建一个对象,对于像sucre这样的字符串要记得加引号
- var obj = {
- userName: 'sucre',
- password: 'secret',
- age: 27
- };
- // 将其转换为Hash对象
- var hash = $H(obj);
- alert(hash.toQueryString());
- }
- function getValue(){
- var h = $H({name: 'sucre', age: 27, country: 'China'});
- // Equivalent to:
- var hh = new Hash({name: 'sucre', age: 27, country: 'China'});
- // Can then be accessed the classic Hash way
- var country = h.get('country');
- var name = hh.get('name');
- //看到了输出的结果是一样的,说明$H与new Hash是一回事
- alert("h中的country:"+country+"\r\n"+"hh中的name:"+name);
- }
- </script>
- </head>
- <body>
- <form>
- <input type="button" value="转换" onclick="test()" />
- <input type="button" value="取值" onclick="getValue()" />
- </form>
- </body>
- </html>
转载于:https://blog.51cto.com/sucre/410405
prototype中的$H函数的用法相关推荐
- python join_详解Python中的join()函数的用法
函数:string.join() Python中有join()和os.path.join()两个函数,具体作用如下: join(): 连接字符串数组.将字符串.元组.列表中的元素以指定的字符(分隔符) ...
- python中time函数用法_python中time tzset()函数实例用法
在时间的设置方面,为了能够跟系统时间有更好的区分,我们有时会借用一些函数方法来实现.就拿tzset()来说是设置时间的一种方法,其内在的变量依靠TZ的控制,如果没有设置TZ则以系统时间为准.接下来我们 ...
- MapInfo中常用查询函数及用法
MapInfo中常用查询函数及用法: 函数用途 语法 备注 图层中选点 Str$(obj)="point": Str(String)表示字符串:point表示点: 图层中选线 St ...
- php中msubstr,PHP学习:thinkphp中字符截取函数msubstr()用法分析
<PHP学习:thinkphp中字符截取函数msubstr()用法分析>要点: 本文介绍了PHP学习:thinkphp中字符截取函数msubstr()用法分析,希望对您有用.如果有疑问,可 ...
- matlab fopen函数的用法,matlab中关于fread函数的用法
公告: 为响应国家净网行动,部分内容已经删除,感谢读者理解. 话题:matlab中关于fread函数的用法 问题详情:用fread打开一个时,需要不需要把开放在某个特回答:必须在Matlab可以搜索的 ...
- Python:Numpy库中的invert()函数的用法
Numpy库中的invert()函数的用法 官方解释: Compute bit-wise inversion, or bit-wise NOT, element-wise. Computes the ...
- Vue中的 h 函数
Vue中的 h 函数 在了解 h 函数之前,我们需要先了解 虚拟DOM, 什么是 虚拟DOM? 虚拟DOM 是使用JS 对象模拟真实的DOM结构,用JavaScript 对象描述DOM 的层次结构.D ...
- pythonaxis函数_Python中numpy.apply_along_axis()函数的用法
numpy.apply_along_axis(func, axis, arr, *args, **kwargs): 必选参数:func,axis,arr.其中func是我们自定义的一个函数,函数fun ...
- Vue3中TSX和h函数的用法
Vue3中TSX的用法 补充:(jsx用法)[https://github.com/vuejs/babel-plugin-jsx] (vue3中渲染函数&JSX)[https://cn.vue ...
最新文章
- 俄研发新无线传电系统 隔20cm保持80%传输效率
- 使用brew安装Logstash(Mac)
- c#将http调用返回额json中的有关中文的unicode转换为中文
- 牛客题霸 [ 有重复项数字的所有排列] C++题解/答案
- 常见浏览器兼容性问题及解决方案
- Java笔记(四)各类容器,set,map,队列实现
- 窗体间跳转及传值 01
- 如何制作一个简单的游戏 Cocos2d x 2 0 4
- java opencv教程_史上最全 java 集成 opencv 教程
- SQLServer2008R2密钥
- 1992-2020年全国大学生数学建模竞赛国家一等奖论文/美赛/认证杯
- JDK15安装与环境变量配置
- 家庭局域网_如何查看局域网内所有ip?
- android登录ins,在android中集成instagram身份验证
- python汽车租赁系统django
- 计算机有哪些交叉专业研究生,与理工科交叉的计算机专业考研方向有哪些?
- wamp mysql 用户名_wamp的mysql设置用户名和密码
- 小程序分享,禁用分享,解除禁用分享
- 小博无线技术团队使用的编程语言
- 移动端实现拖曳核心思想