[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Whether to pass a javascript object to a function or id

Posted on 2016-10-20
3
Medium Priority
?
84 Views
Last Modified: 2016-10-25
HI,
I am making a search filter...
And how i am intending it to give it to user... is ...like :
user will provide the following html in its file :
<div id="filter"/>
And then in js will invoke my library with the parameter filter
And my code will replace this div with the search filter html and everything else....

Now there is an  alternative approach to this :
User can create a $('#filter') and pass it to my function or any other javascript object DOM Node etc...

Which approach is better passing the id as a string or passing an object... and which one....

Also the search filter html which i will return should append to this div element or replace this element ?

Thanks
0
Comment
Question by:Rohit Bajaj
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 7

Assisted Solution

by:Thomas Wheeler
Thomas Wheeler earned 500 total points
ID: 41852679
I would use the ID rather than the object that way you know what it is you are getting.
0
 
LVL 53

Assisted Solution

by:Ryan Chong
Ryan Chong earned 500 total points
ID: 41853172
in my opinion, it's depending on the tasks you're doing in your function. There is no absolute answer for right or wrong to either passing an ID or the object itself to the function since we can do handling in both ways.

it's also a bit of engineer's behavior to determine which approach is preferred, one my feel it's easy and more controllable in one way but another person could have a different opinion.
0
 
LVL 59

Accepted Solution

by:
Julian Hansen earned 1000 total points
ID: 41853373
Normal plugin behaviour is

$('.selector').filter()

Open in new window

However, as you are replacing the element another option would simply be
<div class="my-unique-filter-class-name"></div>

Open in new window


When your library loads
$('.my-unique-filter-class-name').each(function() {
   // replace with your widget here
});

Open in new window


User does not have to do anything other than add the right class to their element.
0

Featured Post

Plesk WordPress Toolkit

Plesk's WordPress Toolkit allows server administrators, resellers and customers to manage their WordPress instances, enabling a variety of development workflows for WordPress admins of all skill levels, from beginners to pros.

See why 2/3 of Plesk servers use it.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Originally, this post was published on Monitis Blog, you can check it here . It goes without saying that technology has transformed society and the very nature of how we live, work, and communicate in ways that would’ve been incomprehensible 5 ye…
Australian government abolished Visa 457 earlier this April and this article describes how this decision might affect Australian IT scene and IT experts.
This video teaches users how to migrate an existing Wordpress website to a new domain.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question