[Javascript] __Index metamethod
[Javascript] __Index metamethod
Does Javascript have metatables and/or metamethods, like Lua? If it doesn't, how can I achieve a rasult similar to __index?
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
- Roland_Yonaba
- Inner party member
- Posts: 1563
- Joined: Tue Jun 21, 2011 6:08 pm
- Location: Ouagadougou (Burkina Faso)
- Contact:
Re: [Javascript] __Index metamethod
The answer is it depends on what you're using it for.
If it's to simulate a class inheritance scheme, you use the function.prototype.member syntax and copying between objects.
If it's to simulate python's getattr/setattr, then no, Javascript doesn't have that kind of feature yet but the next ECMA standard is supposed to have one (get and set functions).
If it's to simulate a class inheritance scheme, you use the function.prototype.member syntax and copying between objects.
If it's to simulate python's getattr/setattr, then no, Javascript doesn't have that kind of feature yet but the next ECMA standard is supposed to have one (get and set functions).
Re: [Javascript] __Index metamethod
Code: Select all
If it's to simulate python's getattr/setattr, then no, Javascript doesn't have that kind of feature yet but the next ECMA standard is supposed to have one (get and set functions).
Code: Select all
var t = ['NULL', 'Mark', 'Jack'];
n = {USERCOUNT}; //I don't know if this syntax is common or if it's relative to the forum I'm editing, anyway that gets a number equal to the number of users
for (i = 1; i <=n; i++) {
document.write(t[i]+"<br />");
}
Code: Select all
Mark
Jack
undefined
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
Re: [Javascript] __Index metamethod
I think the closest approximation is the Firefox extentions to javascript, one of which is __noSuchMethod__. However, being both javascript and firefox, and not lua or love, it's probably way off topic for this forum. You might want to search around on StackOverflow for a while to see what answers you can find.
Re: [Javascript] __Index metamethod
That's why I posted in "General" and not in SupportInny wrote:it's probably way off topic for this forum
Anyway, if it's only Firefox that can help me I think that "undefined" instead of the username will be ok. Thanks, anyway
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
Who is online
Users browsing this forum: Bing [Bot] and 3 guests