GithubHelp home page GithubHelp logo

Confusing re-assignment about didact HOT 3 CLOSED

pomber avatar pomber commented on June 18, 2024
Confusing re-assignment

from didact.

Comments (3)

al3ksandrsafonov avatar al3ksandrsafonov commented on June 18, 2024 4

It's not a variable, so we don't overwrite nothing! It is an object, so we just change a link on it.
When index = 0 we have in memory the object newFiber_0 and 3 links on it:
newFiber => newFiber_0
wipFiber.child => newFiber_0 after operation wipFiber.child = newFiber
prevSibling => newFiber_0 after prevSibling = newFiber
Then index = 1 and we have in memory 2 objects(newFiber_0 and newFiber_1) and 3 links:
newFiber => newFiber_1
wipFiber.child => newFiber_0
prevSibling => newFiber_0
The operation prevSibling.sibling = newFiber adds the link on the object newFiber_1 to the object newFiber_0, so we have:
newFiber => newFiber_1
wipFiber.child => newFiber_0
wipFiber.child.sibling => newFiber_1
prevSibling => newFiber_0
After operation prevSibling = newFiber:
newFiber => newFiber_1
wipFiber.child => newFiber_0
wipFiber.child.sibling => newFiber_1
prevSibling => newFiber_1
Then index = 2 and we have in memory 3 objects(newFiber_0, newFiber_1, newFiber_2) and links:
newFiber => newFiber_2
wipFiber.child => newFiber_0
wipFiber.child.sibling => newFiber_1
wipFiber.child.sibling.sibling => newFiber_2
prevSibling => newFiber_2
And so on...

from didact.

joshuaalpuerto avatar joshuaalpuerto commented on June 18, 2024 1

Wow @al3ksandrsafonov Thank you for you explanation I get it now. Basically it mutates the wipFiber.child since prevSibling has link to the newFiber object.

from didact.

dbwcooper avatar dbwcooper commented on June 18, 2024

@joshuaalpuerto @al3ksandrsafonov , thanks for you explanation, the key point is object is reference type.

from didact.

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.