Node.js Tutorial for Beginners - 10 - Shared State of Modules

preview_player
Показать описание
Рекомендации по теме
Комментарии
Автор

Who's Emily? Where's Wendy?! What did you do to her?!!

AntonMikhaylov
Автор

IMPORTANT: in app.js order of require statements matters. I added bucky b4 emily and the output was different. It LOOKED as if they are not shared.

ojasio
Автор

mmmm. The Notebook + Node. I love this dramatic mix.

CASMANWHAT
Автор

Good Will Hunting is my favourite as well :)

pavlevod
Автор

how did you import buck and emily without export it?

johnnguyen
Автор

its not working for me please help me out i think they have fuxed this bug...not sure so please help me out..

rashmitpankhania
Автор

If you do it w/out the function, so the value is shared between objects, is it also thread

wcdeich
Автор

so what would happen if you write require('./bucky') first and then require('./emily');

rajshreegavel
Автор

Hey Bucky, couldn't you export a prototype if you wanted your own copy of the variables?

camelCaseFTW
Автор

for Bucky's favorite movie, I keep getting NaN. I have checked the code multiple times. I cannot figure it out. Anyone else get this or know why I am getting it?

ryanschatz
Автор

So apparently, the modules SHARE their state with each and every other module that requires them.

Say if a.js had this code

module.export = {
var x = " "
}

and b.js and c.js both want this code it'll be like this in both of them

var Variable = require ("./a")

and if b.js were to change the value of x by

Variable.x = "changedValue"

then c.js, if it does NOT meddle with the value of x, would do this

console.log(Variable.x)
// prints out changedValue in c.js code, which did NOT alter the value of x at all.

so, in conclusion, c.js shares the SAME state of a.js module that was exported to b.js as well. ANY change made by b.js in the module is ALSO reflected in c.js. Hence the SHARED state of modules.

This would be a useful functionality in say... a chatroom. where a chatlog needs to be consistent for each and every user.

P.S : apparently, according to a comment on this very video by TheMeIsOut, this 'bug' was fixed in 2016. so is b.js does change the variable x exported by a.js, the console.log of the SAME variable being exported to c.js would NOT reflect the changes made by b.js .

smyasir
Автор

we are not using any module.exports object in 'emily.js' and 'bucky.js' rather we are using require() in 'app.js'
How it is possible??

gouthamk
Автор

the var movies
is it just a coincidence that both the module name and var have the same name? if not, why?
why didnt you use a different var name for bucky.js ?
also how did you import bucky and emily without exporting them??
pls answer

humaidkidwai
Автор

Dude, it's ok to admit that you liked "The Notebook". lol

sajateacher
Автор

hi bucky, please make a bigggg tutorial series on web designing... 
pls BOSS =D

misabic
Автор

OH, so modules are "static by default" in C# / C++ speak

wcdeich
Автор

Just change the order of require objects, set bucky on top and then he will not get any value.

JOTTABYTE
Автор

var book = require('./library');
console.log("Bucky's favorite book is: " + book.favMovie);

siraajbutler
Автор

Bucky, make videos in MacOS =] OS X is good =] Join our side! =] Force be with you =]

richardmcconnell