2

I have a jQuery plugin. One of the options is what easing method to use for animations. I want to be able to check if the easing method is defined, before I go on and call the $.animate(...) function with the specified easing method. Like so:

var easingMethod = option.easing;
if (!IsDefined(easingMethod)) easingMethod = 'linear';

What would be IsDefined() function?

I could do if (typeof(easingMethod)==undefined) but typeof(easingMethod)==='string'. I'm thinking more along the lines of

function isDefined(s) {
   // If a method named 's' is defined, return true, else false
}

And I have no idea how to do that.

JJJ
  • 32,902
  • 20
  • 89
  • 102
Zia Ur Rehman
  • 1,141
  • 2
  • 11
  • 20

1 Answers1

3

How about this?

function isDefined(s) {
  return $.easing.hasOwnProperty(s);
}
robertklep
  • 198,204
  • 35
  • 394
  • 381