JS里有指针么?
来源:互联网 发布:阿里云上传个人网页 编辑:程序博客网 时间:2024/04/29 20:51
提到 js 指针,其实我是懵圈儿的,准确来说,应该是没有的,引用倒是满天飞。不过下面的这个例子值得看看。
Are there pointers in javascript?
No, JS doesn’t have pointers.
Objects are passed around by passing a copy of a reference. The programmer cannot access any C-like “value” representing the address of the object.
Within a function one may change the contents of an passed object via that reference, but you cannot modify the reference that the caller had, because your reference is only a copy:
var foo = {'bar': 1};function tryToMungeReference(obj) { obj = {'bar': 2}; // won't change caller's object}function mungeContents(obj) { obj.bar = 2; // changes _contents_ of caller's object}tryToMungeReference(foo);foo.bar === 1; // true - foo still references original objectmungeContents(foo);foo.bar === 2; // true - object referenced by foo has been modified
其他参考
JavaScript 的指针是什么?
备注:我还是觉得js里面是没有指针的,除了this指针,更何况,ES6都没有this了。不过js里面绝对有比C里面的指针更刺激的东西,见如下系列。
汤姆大叔的博客-深入理解JavaScript系列
未完待续
0 0
- JS里有指针么?
- JS 里为什么会有 this
- js判断数组里是否有重复元素的方法
- js判断数组里是否有重复元素的方法
- C指针操作——获取有分隔符字符串里的指定字符
- 有一段jsp的js想把它转换单独js文件夹里怎么改
- C#里使用指针
- c++ 里各种指针
- js颜色选择器的两种实现直接上代码(代码里有一种,附件里是另一种)
- js jquery 在弹出对话框里写内容后获取有动画效果
- js里==和===有什么区别
- js里==和===有什么区别
- Windows 里有什么?
- Windows 里有什么?
- CObject里有什么?
- 踏雪有痕-指针
- JAVA有指针吗?
- Qt里的智能指针
- 使用注解的spring mvc
- 洛谷P2921/BZOJ1589[USACO08DEC]在农场万圣节Trick or Treat on the Farm
- 文件共享神器:NitroShare
- 共享内存之bank冲突
- 绝对空前!!!互联网史上的最大ddos攻击惊艳登场
- JS里有指针么?
- 【28.57%】【codeforces 615C】 Running Track
- 提交github后自动完成habitica habit
- 方法的重写
- springCloud注册中心处理注册事件
- POJ 2251 Dungeon Master(BFS)
- 文章标题
- 串口通信+外部中断
- is waiting for the debugger on port 8100" doing Run or Debug