Can i check whether if my javascript ext-lib such as fancybox plugin have already existed in my page(don’t matter its version)?
I use liferay portlet, it can be place two same portlet in one page, I am already have some script confict now. (Liferay AUI script on layout configuration panel, slider in some assetPublisher …)
Can i check whether if my javascript ext-lib such as fancybox plugin have already
Share
If you are testing for native javascript functions (i.e. built–in or created using javascript), then:
will always work, regardless of which library you are using. e.g. to test if jQuery is available:
I would not trust the jQuery isFunction method for host objects, and if you aren’t testing host objects, typeof is completely reliable.
Edit
Oh, I should add that if you are testing methods of host objects, there are many aspects to consider. The following is sufficient in the vast majority of cases:
It’s worth noting that host objects aren’t required to comply with ECMA-262 (though most modern implementations do to a large extent, at least for DOM objects). There are a number of implementations in use that have host objects that, when tested with
typeofwill return “unknown” or similar, some older ones even threw errors.Some host objects throw errors if tested with
object.prototype.toString.call(hostObject)(which jQuery’s isFunction function uses), so unless you are going to implement a robust isHostMethod function, the above will do in the vast majority of cases.