Discord
Login
Community
DARK THEME

Double meaning of the name.

Are fields and methods with the same name allowed in the class ??

Example

Test = class

constructor = function()

list = []

end

list =function()

list.push(list.length)

end

end

init = function()

test = new Test()

test.list()

test.list()

test.list()

print("test "+test.list)

end


Some programming languages ​​allow this use of duplicate names.

In the documentation for microStudio it is not forbidden anywhere.

I tried something like that once. I don't think it works though. When I tried it, I broke the hitboxes in my dungeon game because I had stolen the variable name from a function as a vector.

I think the main reason is that functions are presented as variables just like a list

No they are not allowed, a property of an object / class can only hold one value :-) I mean nothing is forbidden but if you use the same name for a method of the class and an object field, you will just override one with the other.

Post a reply

Progress

Status

Preview
Cancel
Post
Validate your e-mail address to participate in the community