0

I can't quite seem to figure this out.

I have a function where a parameter filter needs to be a function call that accepts an object built within this function:

function bindSlider(time, filter)
{

   var values = {
     min : 8,
     max : 9
   };

   filter(values);
}

I'm now unsure how to call bindSlider, I thought it'd be something like:

bindSlider(time, function(values) {/*do stuff here and accept values built in bind slider*/});

but this fails with the error:

ReferenceError: fliter is not defined


I know I could do:

function filter(values) {

}

bindSlider(time, filter);

but I want to declare filter differently for each call so a function() {} type pattern is what I'm after.

1
  • write var aa=filter(values); don't call method without reference Commented Dec 18, 2013 at 10:28

2 Answers 2

1

From what I've tested, it does work. Only problem I had was your object used = instead of :. Example:

function bindSlider(time, filter) {
   var values = {
       min: 8,
       max: 9
   };
   filter(values);
}

bindSlider(10, function(values) {
   var html;
   for (var i in values) {
       html = document.getElementById('test').innerHTML;
       document.getElementById('test').innerHTML = html + '<br />' + values[i];
   }
});

JSFiddle

Sign up to request clarification or add additional context in comments.

1 Comment

the = instead of : was actually a cut and paste issue. Good to know I'm not barking up the wrong tree. Still having problem in production. Must be something I'm missing.
0

If you update your code so that the object is properly formatted, you might get rid of the error. Oh, and make sure you're correctly passing in time to the bindSlider function.

var values = {
  min: 8,
  max: 9
};

So:

function bindSlider(time, filter) {

 var values = {
   min: 8,
   max: 9
 };

 filter(values);

}

bindSlider(1000, function (values) {
  console.log(values); // { min: 8, max: 9 }
});

Fiddle.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.