Loading ...
Sorry, an error occurred while loading the content.

RE: [ydn-javascript] YAHOO.lang.isUndefined

Expand Messages
  • carlos.m.vadillo@wellsfargo.com
    Actually there is a very easy way to pass an undefined to a function: Function foo(arg1){...} ... foo(); Javascript does not enforce the presence of arguments
    Message 1 of 4 , Aug 27, 2009
    • 0 Attachment
      Actually there is a very easy way to pass an undefined to a function:

      Function foo(arg1){...}
      ...
      foo();

      Javascript does not enforce the presence of arguments when you call. In the call to foo above the value of arg1 will be undefined.

      Cheers

      - Carlos Vadillo
      (415) 371-4591

      -----Original Message-----
      From: ydn-javascript@yahoogroups.com [mailto:ydn-javascript@yahoogroups.com] On Behalf Of Adam Moore
      Sent: Wednesday, August 26, 2009 1:35 PM
      To: ydn-javascript@yahoogroups.com
      Subject: Re: [ydn-javascript] YAHOO.lang.isUndefined

      On Wed, Aug 26, 2009 at 08:22:47PM -0000, handleyj01 wrote:
      > I feel like I must be missing something... Why does this function exist? As far as I know, it's impossible to pass an undefined variable/object to any function in JavaScript. And in fact, every time I try to use YAHOO.lang.isUndefined I get the error "x is undefined" on the line where I try to use it.
      >
      > Am I wrong? Is there a way to pass an undefined object to a function? The only way I know to test for undefined is:
      >
      > if(typeof(foo) == "undefined") {
      > // do something...
      > }
      >
      > And you can't do this:
      >
      > function isUndefined(ObjToTest) {
      > if(typeof(ObjToTest) == "undefined") {
      > return true;
      > }
      > return false;
      > }
      >
      > In that case, any call to "isUndefined" with an actual undefined object will result in a JavaScript error, right?
      >
      > Any insight is much appreciated!

      var f = function(foo) {
      console.log(YAHOO.lang.isUndefined(foo));
      };

      f();
    Your message has been successfully submitted and would be delivered to recipients shortly.