JavaScript native or jQuery library call

145 Views Asked by At

Is there a way to determine which method is used when doing JavaScript coding. I'm playing around with datejs library and method Date.parse and Javascript Date.parse

How can I know which one is doing its job?

http://jsfiddle.net/wilfff/DL6QZ/2/

var d = "Wed Apr 29 08:53:31 +0000 2009";
function parse_date(date_str) {
    return Date.parse(date_str.replace(/^([a-z]{3})( [a-z]{3} \d\d?)(.*)( \d{4})$/i, '$1,$2$4$3'));
}
$(".foo1").text(parse_date(d));

(remove the External Resources and run again) to view the difference.

Any idea how to handle this?

Cheers!

2

There are 2 best solutions below

0
On BEST ANSWER

For something like this I would do my own check, and I would check for something I know would only exist, if the library is loaded. In this case you can check this:

if(Date.CultureInfo){
   // i know now I'm using the external date library
}else{
   // using the browsers native code
}
2
On

You can check it like this:

if(Date.parse.toString() == 'function parse() { [native code] }'){
    // native method
}

See this