如何检查车把js是否包含在应用程序中?(how to check whether handlebar js is included in the application or not?)

我试图检查车把js是否包含在应用程序的HTML页面中。 但它总是返回“未捕获的参考错误 - 未定义把手”,即使在条件语句中也是如此。 指导我实现这一要求。 提前致谢。

if(Handlebars){ // do something with the templates written }else{ // ... }

I am trying to check whether handlebar js is included in the application's HTML page or not. But it always returns "Uncaught Reference Error - Handlebars is not defined" even in the conditional statement. Guide me to achieve this requirement. Thanks in advance.

if(Handlebars){ // do something with the templates written }else{ // ... }

最满意答案

试图在全局范围内访问未定义的变量将始终抛出一个ReferenceError ,但是有一个简单的解决方案 - 只需用if (window.Handlebars)替换if (Handlebars) if (window.Handlebars) 。

Trying to access an undefined variable on the global scope will always throw a ReferenceError, but there's a simple solution - just replace if (Handlebars) with if (window.Handlebars).

如何检查车把js是否包含在应用程序中?(how to check whether handlebar js is included in the application or not?)

我试图检查车把js是否包含在应用程序的HTML页面中。 但它总是返回“未捕获的参考错误 - 未定义把手”,即使在条件语句中也是如此。 指导我实现这一要求。 提前致谢。

if(Handlebars){ // do something with the templates written }else{ // ... }

I am trying to check whether handlebar js is included in the application's HTML page or not. But it always returns "Uncaught Reference Error - Handlebars is not defined" even in the conditional statement. Guide me to achieve this requirement. Thanks in advance.

if(Handlebars){ // do something with the templates written }else{ // ... }

最满意答案

试图在全局范围内访问未定义的变量将始终抛出一个ReferenceError ,但是有一个简单的解决方案 - 只需用if (window.Handlebars)替换if (Handlebars) if (window.Handlebars) 。

Trying to access an undefined variable on the global scope will always throw a ReferenceError, but there's a simple solution - just replace if (Handlebars) with if (window.Handlebars).