Reputation: 10230
Hey guys i was just going through the code inside modal.js , it s jquery plugin .
you can check it out here , line 284 .
can somebody explain what the below line is really doing ? espically this part :
data[option](_relatedTarget)
is the above line calling a function or passing a parameter , what exactly is it doing ??
if i console.log(data[option])
, i get Modal.prototype.hide()
on document load and
function Modal.prototype.toggle()
when i click on the launch button .
if i console.log _relatedTarget i get undefined on document load and
<button data-target="#myModal" data-toggle="modal" class="btn btn-primary btn-lg">
when clicking on launch button.
put together though , what exactly is this line doing ?
data[option](_relatedTarget).
Heres a demo of the plugin in action : Demo.
Its critical for me to understand what that perticular line is doing for certain. would appreciate any explanation , if i am not clear about anything , please tell me so in the comments , i'll try being clearer .
Thanks .
Alexander.
Upvotes: 0
Views: 62
Reputation: 9921
data[option]
is using variable indexer on data
to get its option
property.
The value of of this property may change, as you've seen, but in both cases, it represents a method, either hide()
or toggle()
.
_relatedTarget
is a parameter to the method, presumably designating which element should be hidden or toggled.
Upvotes: 2