简体   繁体   中英

Operator overloading in V8

This might be a simple question, but I couldn't find anything about this subject on google.

Obviously this isn't possible in pure javascript, but let's say I'm creating some sort of container class in V8 and passing that class back to javascript. Can I implement operator overloading in V8 so that it's possible to access array elements in JS like foo[i] , or am I stuck with foo.at(i) or similar method calls?

Thanks!

You can already do this without overloading; you can use bracket notation to access your own object's properties:

function Foo() {
  for (var i=0; i<arguments.length; i++)
    this[i] = arguments[i]
}

var foo = new Foo(1,2,3)

foo[1] //=> 2

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM