你会如何在javascript中重载[]运算符 [英] How would you overload the [] operator in javascript

查看:169
本文介绍了你会如何在javascript中重载[]运算符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎找不到在javascript中重载[]运算符的方法。那里的任何人都知道吗?

I can't seem to find the way to overload the [] operator in javascript. Anyone out there know?

我在考虑... ...

I was thinking on the lines of ...

MyClass.operator.lookup(index)
{
     return myArray[index];
}

或者我没看正确的事情。

or am I not looking at the right things.

推荐答案

你不能在JavaScript中重载运算符。

You can't overload operators in JavaScript.

它是建议用于ECMAScript 4 但遭到拒绝。

我认为你很快就会看到它。

I don't think you'll see it anytime soon.

这篇关于你会如何在javascript中重载[]运算符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆