Skip to main content
Stack Overflow
  1. About
  2. For Teams

Return to Revisions

3 of 4
added 2 characters in body
user3757174
  • 523
  • 2
  • 9
  • 17

Javascript — objects containing functions with parameters

This is a fairly simple question, but I can't seem to find an example online. I've read up on objects and functions (i.e. here), but can't seem to find an example of a function within an object that accepts parameters.

In JavaScript, we can create an object, a nested object, and a method defined by a function:

var testObject = {
 nestedObject : {
 isNumber : function(number) { return !isNaN(number) };
 }
}

How can I call my function with a specific parameter? Is the following correct?

testObject["nestedObject"].isNumber(number)

Thanks!

user3757174
  • 523
  • 2
  • 9
  • 17
lang-js

AltStyle によって変換されたページ (->オリジナル) /