Известно, что в Javascript параметры функции передаются только по значению, нельзя передать параметр простого типа по ссылке.

О чем это мы? В программировании существует два способа передачи параметров функции: по ссылке и по значению. Когда параметр передается по значению, то функция только использует это значение, значение фактической переменной изменить она не в силах, даже если в функции переменной присваивается новое значение, как только функция закончит работу, значение нашей переменной станет прежним, каким оно было до работы функции. Когда параметр передается по ссылке, то изменение значения переменной внутри функции происходит реально и на выходе из функции наша переменная уже имеет новое значение. Это очень нужная штука, а в Javascript она не работает. 

Однажды делел я проект с бооольшим количеством однотипных объектов и прогнозировать изменение переменных было невозможно, путь был один: заставить сценарий изменить значение входной переменной и вот, как я это реализовал.

В моей таблице стилей CSS задано 2 объекта. Объект с id="d1" имеет ширину 150 px, объект с id="d2" имеет ширину 200 px:

#d1 { width: 150px; }
#d2 { width: 200px; }

В HTML-коде заданы оба объекта (я не привожу этот фрагмент за его несущественностью) и два вызова функции. При первом вызове функция processDecreaseWidth будет изменять значение атрибута width для первого объекта, при следующем вызове функция будет изменять значение атрибута width для второго объекта. Функция processDecreaseWidth имеет два входных параметра. Первый параметр - это id, по которому определяется, с каким объектом работать. Второй параметр - соответствует изменяемой переменной, отвечающей за ширину объекта.

Привожу фрагменты вызова функций:



В сценарии на Javascript сначала задаются интересующие нас переменные. Им присваиваются начальные значения ширины объектов, те же, что и в таблице стилей CSS:

var thisWidthD1=150;


Затем следует код функции, где ElId - id объекта, thisWidth - ширина объекта. Сначала функция присваивает переменной thisWidth значение новой ширины, затем обрабатываемому объекту присваивается новая ширина:

function processDecreaseWidth(ElId,thisWidth)
    if (thisWidth > 2) 

Обратите внимание, в конце функции processDecreaseWidth вызывается функция reformWidth, которая присваивает переменным, отвечающим за ширину объекта, новые значения. Вот код этой функции:

function reformWidth(ElId,thisWidth)
    switch (ElId)
        case "d1": thisWidthD1=thisWidth;
        case "d2": thisWidthD2=thisWidth;

Недостаток этого способа в том, что при большом количестве объектов объем кода последней функции страшно разрастется, как впрочем и все фрагменты присвоения данных и задания объектов.

Добавить комментарий


0 # Francesco 21.04.2021 19:08
Just desire to say your article is as surprising.

The clearness for your put up is just great and i can think you are a professional in this
subject. Well together with your permission allow me
to grab your RSS feed to keep up to date with imminent post.
Thank you a million and please keep up the rewarding work.

my page: increase web
site traffic: https://www.pinterest.ca/pin/734368282973377761/
Ответить | Сообщить модератору
0 # Hayley 21.04.2021 04:45
link: http://we-b-tv.com/serialx/sitemap1.xml
Ответить | Сообщить модератору
0 # Lea 21.04.2021 02:01
fr: http://we-b-tv.com/serialx/serial-427-s-576.html
Ответить | Сообщить модератору
0 # Darrin 20.04.2021 15:51
site: https://www.instagr.am/batmanapollo
Ответить | Сообщить модератору
0 # Chante 18.04.2021 14:52
edu: http://animalporn.top/video.php?movie=http%3a%2f%2fbatmanapollo.ru
Ответить | Сообщить модератору
0 # Belinda 17.04.2021 08:16
Выживший смотреть онлайн просмотр: http://bit.ly/2S4LEjy
Ответить | Сообщить модератору
0 # Dena 16.04.2021 20:52
Of course, what a fantastic blog and revealing posts, I surely will bookmark your blog.Have an awsome

Also visit my web-site; google news optimization: https://www.pinterest.com/pin/173881235602634279/
Ответить | Сообщить модератору
0 # Darwin 14.04.2021 14:04
This is very interesting, You're a very skilled blogger. I've joined your feed and look forward to seeking more of your wonderful
post. Also, I've shared your site in my social networks!
viagra: https://viagrasildenafilok.com/ https://viagrasildenafilok.com/
Ответить | Сообщить модератору
0 # Lieselotte 10.04.2021 12:36
Right now it appears like Expression Engine is the top blogging platform out there
right now. (from what I've read) Is that what
you're using on your blog?

Feel free to visit my web blog - hop over to this web-site: http://polllilo21q.blog.fc2.com/blog-entry-1376.html
Ответить | Сообщить модератору
0 # Lazaro 09.04.2021 13:20
Hmm is anyone else encountering problems with the images on this blog loading?
I'm trying to find out if its a problem on my end or if it's the blog.
Any feed-back would be greatly appreciated. absolute dating: https://datingsitesww.com
Ответить | Сообщить модератору
0 # Norine 08.04.2021 16:27
It's remarkable to pay a visit this web page and reading the views of all friends concerning this
article, while I am also keen of getting experience. free
dating: https://onlinedatingtind.com/ https://onlinedatingtind.com/
Ответить | Сообщить модератору
0 # Penny 08.04.2021 08:16
If you would like to get a good deal from this paragraph then you
have to apply these methods to your won website.
local dating: http://onlinedatingdd.com/ http://onlinedatingdd.com/
Ответить | Сообщить модератору
0 # Ursula 07.04.2021 19:16
This is the right website for anyone who really wants to find out about this topic.
You know a whole lot its almost hard to argue with you (not that I personally would want to…HaHa).
You certainly put a brand new spin on a topic that has been discussed for years.

Great stuff, just excellent! Dating App: http://onlinedatingdd.com/
Ответить | Сообщить модератору
0 # Ara 07.04.2021 16:51
Fantastic beat ! I would like to apprentice while you amend your web
site, how could i subscribe for a blog web site?
The account aided me a acceptable deal. I had been tiny bit acquainted of this your
broadcast provided bright clear idea speed dating: http://onlinedatingdd.com/ http://onlinedatingdd.com/
Ответить | Сообщить модератору
0 # Kennith 06.04.2021 06:06
Every weekend i used to visit this web site, as i
want enjoyment, for the reason that this this website conations
in fact nice funny material too. viagra pills: https://viagrasildenafilok.com/ https://viagrasildenafilok.com/
Ответить | Сообщить модератору
0 # Laurene 15.03.2021 20:26
What's up, this weekend is good designed for me, for the reason that this point in time i am reading this impressive educational article here at my home.
Ответить | Сообщить модератору
0 # Carmelo 11.03.2021 13:31
Thank you a lot for sharing this with all people you really recognise what you're speaking
approximately! Bookmarked. Please additionally
visit my web site =). We can have a link change arrangement among us

Here is my web site: best fiji
kava: https://bestfijikava.com/shop-kava/
Ответить | Сообщить модератору
0 # Rosella 11.03.2021 13:17
This is a topic which is near to my heart... Thank you! Exactly where are your contact details though?

Feel free to surf to my homepage: Five Duct
Deficiencies That Could Lead to Problems With Your HVAC: https://sandium.com/general-hvac/five-duct-deficiencies-that-could-lead-to-problems-with-your-hvac.html
Ответить | Сообщить модератору
0 # Deangelo 11.03.2021 11:03
The latest along with the most talked-about wi-fi technology
may be the NFC or Near Field Communication, which lets
users exchange data by tapping their devices together.
However, they have got neither the pace of thermal printers nor
period of time costs of dot matrix printers. The widely using USB is really because
its small size and enormous capacity, portable characteristics,
if USB to manipulate and manage the let customers use up
very trouble then use of USB disk run counter on the original intention.

Also visit my homepage Carrier Air Conditioners: http://esgashton.us/__media__/js/netsoltrademark.php?d=www.paulzip.com%2F__media__%2Fjs%2Fnetsoltrademark.php%3Fd%3Dd-click.armazemdanoticia.Com.br%252Fu%252F18887%252F88%252F31%252F5_0%252F1fb90%252F%253Furl%253Dhttp%253A%252F%252Fwww.cartridgeonwheelsreno.com%252F
Ответить | Сообщить модератору
0 # Laurie 11.03.2021 09:20
This post is great! I read your blog fairly often and you're
always releasing some great stuff. I'll make sure to share this on my Facebook page and my followers should like this
also. Keep up the good work!

Feel free to surf to my homepage :: anchortext: http://mmbguild.org/forums/topic/essential-recommendations-you-must-know-before-hiring-a-lawyer/
Ответить | Сообщить модератору
0 # Theo 11.03.2021 08:43
Acer travel mate series supplies a blend
of ultra portability and performance. However, they have got
neither the pace of thermal printers nor the lower costs of dot matrix printers.

Did you know that empty printer inkjet cartridges from your printer were fully-capable of polluting environmental surroundings
beyond levels unimaginable.

my blog: Drugs To Treat Ibs Pain: http://marcsazer.com/__media__/js/netsoltrademark.php?d=portal.sitecom.com%2FWLM-3600%2Fv1001%2Fupgrade%2Fparent.php%3FlanIP%3D192.168.0.1%26userRequest%3Dcartridgeonwheelsreno.com
Ответить | Сообщить модератору
0 # Osvaldo 11.03.2021 08:18
If you print often, maybe more often than once every day, you should be mindful of the type
of your cartridge you happen to be using. Accsense Product Manager Dana Kennedy explains his enthusiasm:
"Increasingly we're focusing on expanding the ability of our Accsense systems to the market's specific needs, so that we're now storing the servers ourselves and offering direct support. Eventually, consumer electronics manufacturers started for the probability of automating domestic microcontroller based devices.

Also visit my site ... =20href=https:/ /www.cartridgeo nwheelsreno.com /canon-ink-tone r-cartridge-on- wheels-reno/]tr eating Ibs with diarrhea And constipation: http://Penza-Job.ru/phpinfo.php/RK=0/RS=ZHXiXBvz_xt_lczKMCAp4T2Kpe0-?a[
Ответить | Сообщить модератору
0 # Beatriz 11.03.2021 07:40
One thing about luxury furniture is which it acts being a seductive temptress.
The appropriate sized the chimney is the fact that that
is bigger than that regarding the outer lining portion of the
gas stove. It is for this reason that you have a number of kitchen worktops that you are able to choose what suits your
kitchen area best.

Feel free to surf to my web site :: irritable bowel
syndrome Treatments: http://1Gr.cz/log/redir.aspx?r=pb_0_16&url=https://www.bridgesconst.com/ultracraft-cabinetry/
Ответить | Сообщить модератору
0 # Carl 01.03.2021 14:34
If some one wants to be updated with most recent technologies therefore he must be pay a
visit this web site and be up to date daily.
Ответить | Сообщить модератору
0 # Lauri 16.02.2021 16:02
First of all I would like to say superb blog!
I had a quick question that I'd like to ask if
you do not mind. I was interested to find out how you center yourself and clear
your mind prior to writing. I've had trouble clearing my mind in getting my ideas out.
I truly do enjoy writing but it just seems like the first 10 to 15 minutes tend to be lost just trying
to figure out how to begin. Any suggestions or tips?
Ответить | Сообщить модератору
0 # Dorris 05.02.2021 20:12
Generally I do not learn post on blogs, however I wish to say that this write-up very forced me to try
and do it! Your writing taste has been surprised me. Thank you, quite nice post.
Ответить | Сообщить модератору
0 # Ernestina 24.01.2021 08:44
Ꮪo, the sole advisable option іs tto hold tһе
motor viable ԝith thе aid of regular maintenance.
Ꭺlong with regular servicing annd maintenance,
tһere are ѕeveral οther services tһɑt may Ьe performed by
an auto repair shop. Јust by adding thiѕ one tһing to уour interior can adjust it
cоmpletely ƅy bringing the true personality οf үоur car օr

Visit my homepaցe - ase certification lookup: http://reeboksportsclubnewyork.org/__media__/js/netsoltrademark.php?d=Www.Technologyonthe.net%2F__media__%2Fjs%2Fnetsoltrademark.php%3Fd%3Dwww.iplocationfinder.com%252Fasecertify.com
Ответить | Сообщить модератору
0 # Adele 15.01.2021 03:30
Ꮮooқ att online reviews of tһe car and model to find out what wοrks, what doeѕn't, and that whіch yߋu may һave a much problemѕ with.
The hardest pɑrt iis ɡoing to be installing tһe Aftermarket BMW Radio playeer
іtself. On the otheг hаnd, tһe replacement fгom the lens is an expensive
option ɑnd you also must search for ѡays in order to beat the cost.

my blog; ase heavy duty truck certification: http://Www.learndrawing.com/__media__/js/netsoltrademark.php?d=www.telcosystems.com%2F__media__%2Fjs%2Fnetsoltrademark.php%3Fd%3Dwww.asecertify.com%252Fcompany.htm
Ответить | Сообщить модератору
0 # Marjorie 02.01.2021 17:29
We're a group of volunteers and opening a
new scheme in our community. Your site provided us with valuable
info to work on. You have done an impressive job and our entire community will be grateful to you.

my blog: viagra: http://www.pornvideoshd.net
Ответить | Сообщить модератору
0 # Elane 01.01.2021 04:37
Тhе shifting with the gears iѕ manufactured creaky
once tһe transmission fluid breaks ⅾ᧐wn and never as smooth
аs it shouⅼd bе. They can uѕually allⲟw you to
narrow things down in thе event youu teⅼl tһem whɑtever you're looking foг.
It's not harɗ to sift the honest online dealers frоm tһe shady ones.

my page ase certification training classes: http://verndowns.com/__media__/js/netsoltrademark.php?d=www.asecertify.com%2FAudioStudyMainPage.htm
Ответить | Сообщить модератору
0 # Kaley 28.12.2020 04:52
Thhe latest as well as the most talked-about wi-fi technology is the NFC
or Near Feld Communication, whoch lets users exchange data by tapping their devices together.
Accsense Product Manager Danaa Kennedy explains
his enthusiasm: "Increasingly we're focusing on expanding the ability of our own Accsense systems on the market's specific needs, so that we're now storing the servers ourselves and offering direct support. Eventually, electronics manufacturers started thinking about the possibilities of automating domestic microcontroller based devices.

my blog post: ink cartridges reno: https://Korrespondent.net/default.aspx?page_id=60&lang=ru&stx=%3ca%20href%3dhttp%3a%2f%2fwww.cartridgeonwheelsreno.com%2Fprinter-toner-reno%2F&roi=0&st=1
Ответить | Сообщить модератору
0 # Manuela 24.12.2020 14:12
Boost conversion - how will you define conversion, is it once the user reggisters in your site or whenever a user
buys from the site. In addition, there are countless firms that promised me a guaranteed ranking
on Google, Yahoo and Bing. You really do not wait to press some type off computer button and then use a totally automated money nnet machine.

Feel free to visit my web page ... SEO
wizard Lux: https://www.intersnap.com/search-engine-optimization/seo-wizard-lux-nv/
Ответить | Сообщить модератору
0 # Rashad 22.12.2020 04:39
generic cialis 2 dollar 23 cent cialis pictures how can i buy a low
cost cialis: https://cialisbin.com/# - medicine cialis www cialis over the counter: https://cialisbin.com/# cialis 10mg or
20mg who is online
Ответить | Сообщить модератору
0 # Stepanie 20.11.2020 14:57
viagra black review stendra vs viagra: https://viagenpwr.com/# viagra
buy jump to natural viagra: https://viagenpwr.com/# - viagra side effects with alcohol guestbook.php?a ct= super viagra
Ответить | Сообщить модератору
0 # Franchesca 14.11.2020 07:08
viagra and alcohol side effects interests viagra for sale online: http://viasldnfl.com/# viagra viagra lowest
prices viagra for sale online: http://viasldnfl.com/# - trackback einen kommentar hinterlassen viagra purchase of viagra and
viagra pills
Ответить | Сообщить модератору
0 # Young 17.05.2020 08:41
buy generic viagra pills online sophia viagra hot: http://viagrawinner.com/# viagra 10mg or 20mg legend sophia viagra: http://viagrawinner.com/#
- viagra online uk cheap viagra tadalafil generic
Ответить | Сообщить модератору
0 # Aretha 04.04.2020 05:52
viagra safety buy generic viagra online: http://viagenmdx.com/# buy viagra online email
e-mail over the counter viagra cvs: http://viagenmdx.com/# - viagra 10 mg 4 tablet display posts from previous viagra pills price edit options
Ответить | Сообщить модератору
0 # Sommer 03.04.2020 04:14
coronavirus fatality rate chloroquine phosphate
250 mg: http://chloroquine-phosphate-250mg.com/# coronavirus 6th remdesivir and chloroquine: http://chloroquine-phosphate-250mg.com/# -
coronavirus 5 million coronavirus zero patient
Ответить | Сообщить модератору
0 # Hye 01.04.2020 03:37
online viagra generico generic name
for viagra: http://viagenmdx.com/# viagra generic online in descending
order online viagra: http://viagenmdx.com/# - viagra for women dosage registered users viagra information blog not logged in
Ответить | Сообщить модератору
0 # Cortez 29.03.2020 22:40
vardenafil viagra viagra order viagra online: http://viagenusa.com/# uk sales
viagra and viagra generic viagra usa pharmacy: http://viagenusa.com/# - viagra
5mg generic replies high doses of viagra
Ответить | Сообщить модератору
-1 # Precious 27.03.2020 19:37
coronavirus 75 alcohol chloroquine drug: http://chloroquine-cureforcoronavirus.com/# coronavirus 0.12 micron buy chloroquine online: http://chloroquine-cureforcoronavirus.com/# - coronavirus 2020 symptoms 2 coronavirus in usa
Ответить | Сообщить модератору
0 # Phoebe 16.03.2020 06:21
viagra and alcohol side effects all times are utc
usa made generic viagra
for men: http://genviagrafx.com/# canadian pharmacy viagra 20mg joined pills for sale: http://genviagrafx.com/# - order cheap viagra
viagra, viagra and levitra
Ответить | Сообщить модератору