On Dec 3, 12:56 am, Matt Kruse <m...@mattkruse .comwrote:
On Dec 2, 3:14 am, VK <schools_r...@y ahoo.comwrote:
// # conditional compilation needs a condition;
No it doesn't. It will run in the JScript engine,
and won't elsewhere. No need for a condition.
You are wrong: the minimum required syntax for pragma reader is:
/*@cc_on @ */
/*@if (some_condition )
// some source code
@else @*/
// some source code
/*@end @*/
The code you have originally posted simply leads to the "syntax error"
on IE. Without closing @end pragma it is still syntax error but more
informative: about missing end pragma. Sometimes it is not needed to
build any complex condition and the question only is "IE or not IE".
In such case one normally uses @if (@_jscript) check - it always
returns true for IE. So then really minimalistic conditional
compilation syntax is:
/*@cc_on @*/
/*@if (@_jscript)
// some source code
@else @*/
// some source code
/*@end @*/
One of defaults of the current implementation is that there is no
explicit way to write fall-through branching: so "include this if
(true) but also include the rest of source". As a workaround one
normally uses the above block with empty "else" branch:
/*@cc_on @*/
/*@if (@_jscript)
// some source code
@else @*/
// NOP
/*@end @*/
// the rest of code
Pre-processor has to be turned off as soon as not needed anymore.
Don't forget that it is not a parser on this stage - it is pre-
processor preparing text source code to be sent to parser. Don't make
him to keep going through the whole 10Kb - 600Kb js file in search of
more pragma commands. Inefficient first, dangerous second - in case of
same obfuscated source on the go.
// # if - else if - else, no pending 'if'
// # Not an error but if it's for public
// # attention then let's be accurate ;-)
else if (typeof o=='object') {
No need for else if the first block returns early from the function.
OK
// # On IE for DOM elements implicit toString call
// # returns either "function ..." or "[object]"
// # or "unknown" (for some external ActiveX controls):
// # so the 2nd check adds absolutely nothing to the job:
// # /\[native code\]/.test(o) removed
Actually, it is needed. In your version,
isFunction( ["function"] )
would return true.
On what browser? Again, you seem mixing property values of objects and
toString return value of object itself: they have nothing to do with
each other unless overloaded toString.
// * If you want to know about RegExp instances
// * then check for RegExp instances!
I suppose. I've never used isPrototypeOf, so I'd have to make sure
that it's a good choice to use it in this case.
You are not making a startup stage feature sniffing: you are making a
method for using runtime, possibly with hundreds and more calls at a
short period of time. In such case the proportion "more checks / more
speed" has to be shifted to "more speed" especially when the language
provides legal tools for it. IMHO.
// # Switch pragma reader off:
/*@end @*/})();
Not really necessary.
See the top of my post.
/*@end @*/