Log in

No account? Create an account

Catch undefined method calls in JS - Web Developer

About Catch undefined method calls in JS

Previous Entry Catch undefined method calls in JS Jul. 21st, 2012 @ 12:51 am Next Entry

There is an interesting task. I need to catch any undefined calls in my JS code. Is there a solution?

    function a() {
        alert('Hi, I'm a function!');

    a(); // works great

    a.b(); // call undefined function

So, are there any ways to catch calls a.b() in my function a()?
Leave a comment
[User Picture Icon]
Date:July 20th, 2012 10:05 pm (UTC)
I would say no. You could check if a.b == undefined....
[User Picture Icon]
Date:July 20th, 2012 11:06 pm (UTC)
I never know 'b', 'c' or 'd' will be called :) But I've to know what nonexistent function was called.
[User Picture Icon]
Date:July 21st, 2012 05:29 am (UTC)
just put them into try-catch block
Date:July 21st, 2012 01:00 pm (UTC)
I think, that victorgr says about method calls interception such like in PHP (__call).

No, you can't.

Edited at 2012-07-21 01:01 pm (UTC)
[User Picture Icon]
Date:July 21st, 2012 01:29 pm (UTC)
You are completely right. Like __call in PHP or the same thing in Ruby.

Thank you for your answer!
(Leave a comment)
Top of Page Powered by LiveJournal.com