GithubHelp home page GithubHelp logo

the table is not copy~~ about 30log HOT 5 CLOSED

yonaba avatar yonaba commented on August 25, 2024
the table is not copy~~

from 30log.

Comments (5)

zorfmorf avatar zorfmorf commented on August 25, 2024

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.

wilhantian avatar wilhantian commented on August 25, 2024

OH, very sorry, I write too much js, it`s local. very thanks for you!

from 30log.

Yonaba avatar Yonaba commented on August 25, 2024

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.

wilhantian avatar wilhantian commented on August 25, 2024

@Yonaba yes, Its no problem. Now its OK.
非常谢谢。

from 30log.

Yonaba avatar Yonaba commented on August 25, 2024

Awesome! Thanks reporting this.

from 30log.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.