Comments (5)
The problem is that you are assigning a new table to Obj.tab during class creation. This means that all your tables that inherit from Obj will share the same tab table. In your case you want to use the init method provied by 30log as described here.
> class = require '30log'
> Obj = class("Obj")
> function Obj:init() self.tab = {} end
> o1 = Obj:new()
> o2 = Obj:new()
> o1.tab.x = "BuiBuiBui"
> print(o1.tab.x)
BuiBuiBui
> print(o2.tab.x)
nil
>
And what's up with the "var" definition? Did you replace the "local" keyword?
from 30log.
OH, very sorry, I write too much js, it`s local. very thanks for you!
from 30log.
Although @zorfmorf provided a nice solution, the latest commit should provide some fix to the code.
Try this new one, it should be working nicely.
local Obj = class("Obj", {
tab = {}
})
local o1 = Obj:new()
local o2 = Obj:new()
o2.tab.x = "BiuBiuBiu"
print(o1.tab.x) -- outputs nil
print(o2.tab.x) -- outputs BiuBiuBiu
Let me know if everything is okay with commit 8a8ae92. If so, i'll flag with new bugfix version tag.
Thanks.
from 30log.
@Yonaba yes, Its no problem. Now it
s OK.
非常谢谢。
from 30log.
Awesome! Thanks reporting this.
from 30log.
Related Issues (20)
- Inheritance and super HOT 2
- Singleton version HOT 1
- Missing comma HOT 1
- Need help on using new() HOT 7
- No easy way to clone classes. HOT 5
- Double class inheritence super
- isClass return false when using multiple 30log instances HOT 1
- the table is not copy~ HOT 1
- Stack overflow when adding static instance. HOT 2
- Subclasses retain old members after changes to superclass
- way to enumerate all + set/get properties
- Subclasse "capture" super's __subclasses entry
- the "1log"
- Troublesome deep-copy on object instantiation
- test('__ipairs is supported') are unassertive on travis's Lua 5.3 environment HOT 2
- class._VERSION = '30log v1.2.0'
- Mixin is not working when :new method is present HOT 1
- Unused code "c.__instances"
- Bump lua version number to 5.4? All tests pass. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from 30log.