?

Log in

 

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
Hi!

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

Imagine:
    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]
From:valera
Date:July 20th, 2012 10:05 pm (UTC)
(Link)
I would say no. You could check if a.b == undefined....
[User Picture Icon]
From:victorgr
Date:July 20th, 2012 11:06 pm (UTC)
(Link)
I never know 'b', 'c' or 'd' will be called :) But I've to know what nonexistent function was called.
[User Picture Icon]
From:mpak666
Date:July 21st, 2012 05:29 am (UTC)
(Link)
just put them into try-catch block
http://www.w3schools.com/js/js_try_catch.asp
From:nikelin
Date:July 21st, 2012 01:00 pm (UTC)
(Link)
I think, that victorgr says about method calls interception such like in PHP (__call).

@victorgr
No, you can't.

Edited at 2012-07-21 01:01 pm (UTC)
[User Picture Icon]
From:victorgr
Date:July 21st, 2012 01:29 pm (UTC)
(Link)
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