在javascript中,什么是构造函数?什么不是? [英] In javascript, what is a constructor? And what isn't?
问题描述
我正在使用jQuery的插件。它在webkit中运行良好,但是当我在firefox中尝试它时,我得到以下firefox错误:
I'm using a plugin for jQuery. It works great in webkit, but when I try it in firefox I get the following firefox error:
google.maps.Geocoder is not a constructor
$('.to, .from').geo_autocomplete(new google.maps.Geocoder, {
以下是所有jquery:
Here is all the jquery:
$('.to, .from').geo_autocomplete(new google.maps.Geocoder, {
mapkey: 'ABQIAAAAbnvDoAoYOSW2iqoXiGTpYBT2yXp_ZAY8_ufC3CFXhHIE1NvwkxQNumU68AwGqjbSNF9YO8NokKst8w',
selectFirst: false,
minChars: 3,
cacheLength: 50,
width: 235,
scroll: true,
scrollHeight: 330
});
什么是构造函数,以及firefox如何向我指出它?
What's a constructor and howcome firefox is pointing it out to me?
推荐答案
任何本机函数都可以作为构造函数调用(即使它不是设计的)。任何不可赎回的东西lso不能是构造函数。例如 new 3
给出相同的错误。
Any native function may be called as a constructor (even if it wasn't designed to be). Anything that's not callable also cannot be a constructor. eg new 3
gives the same error.
在您的页面中, google.maps。 Geocoder
只是 undefined
,这当然无济于事。查看Google的地图脚本,无法加载Geocoder模块,因为它正在使用 document.write
这样做,一个必须从HTML中包含的< script>
运行的方法解析时的文档,不是像你在这里那样使用DOM脚本导入的。
In your page, google.maps.Geocoder
is simply undefined
, which certainly isn't going to help. Looking at Google's maps script it's failing to load the Geocoder module because it's using document.write
to do so, a method that has to be run from a <script>
included in the HTML document at parse time, not imported by use of DOM scripting as you're doing here.
当然不希望从通过客户端加载的页面运行 - 方XSLT。这将给你很多浏览器问题和零搜索引擎优化的存在。这种疯狂的目的是什么?
It certainly doesn't expect to be run from a page loaded via client-side XSLT. This is going to give you lots of browser problems and zero SEO presence. What is the purpose of this craziness?
这篇关于在javascript中,什么是构造函数?什么不是?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!