我正在使用Google Maps Javascript API v3和RequireJS编写JavaScript应用程序.我为gmaps编写了一个小包装器,以便正确地获取依赖关系:
define('gmaps', ['goog!maps,3.9,packages:[geometry],language:de,other_params:sensor=false&channel=...&client=...'],
function(){
return window.google.maps;
});
Run Code Online (Sandbox Code Playgroud)
即使在使用优化器缩小代码之后,这在大多数情况下都能正常工作.但是,有时我会gmaps.geometry is undefined在一个模块中出现错误,该模块具有gmaps依赖关系并尝试计算距离:
define(['gmaps'], function(gmaps) {
return {
...
calcDistance: function(target) {
var position = this.getPosition();
var distance = gmaps.geometry.spherical.computeDistanceBetween(
new gmaps.LatLng(position.latitude, position.longitude),
new gmaps.LatLng(target.latitude, target.longitude)
);
return (distance / 1000).toFixed(2);
}
}
});
Run Code Online (Sandbox Code Playgroud)
只有当我尝试calcDistance在页面之后执行并且所需数据已加载且有时仅执行时,才会发生这种情况.我想这是gmaps异步加载的一些问题,但我不完全理解它.如何定义gmaps但gmaps.geometry未定义?有没有什么办法解决这一问题?
我有一个标题带,其中包含一个包含计算变量的文本字段.该文本字段有evaluationTime设为报告,同为变量resetType.现在,我正在尝试使用条件样式设置此字段的背景颜色,但我不断收到一条错误消息,说明: $V{avg_perc}
Invalid expression: !Double.isNaN($V{avg_perc}) && $V{avg_perc} >= 0.8
Run Code Online (Sandbox Code Playgroud)
我在做同样的事情用相同的条件样式在列脚注和它的作品没有任何问题,即使我设置evaluationTime对这一领域的报告了.
删除后!Double.isNaN($V{avg_perc})我不再出现错误,但表达式仍然无效.我的字段保持红色,这是任何条件无效时的基本颜色,无论哪个值$V{avg_perc}有.但它仍然可以在Column Footer中使用.这是我的风格:
<style name="avg_color" mode="Opaque" backcolor="#FF0000" pdfFontName="Helvetica-Bold">
<conditionalStyle>
<conditionExpression><![CDATA[$V{avg_perc} >= 0.8]]></conditionExpression>
<style backcolor="#008000"/>
</conditionalStyle>
<conditionalStyle>
<conditionExpression><![CDATA[$V{avg_perc} >= 0.6 && $V{avg_perc} < 0.8]]></conditionExpression>
<style backcolor="#FFCC00"/>
</conditionalStyle>
</style>
Run Code Online (Sandbox Code Playgroud)
使用的字段和变量:
<field name="perc" class="java.lang.Double"/>
<variable name="avg_perc" class="java.lang.Double" calculation="Average">
<variableExpression><![CDATA[$F{perc}]]></variableExpression>
</variable>
Run Code Online (Sandbox Code Playgroud)
知道如何让这个东西工作吗?我在3.7.4版本中使用JasperReports和 …
我原型,Function以便它有一个getBody函数:
Function.prototype.getBody = function() {
// Get content between first { and last }
var m = this.toString().match(/\{([\s\S]*)\}/m)[1];
// Strip comments
return m.replace(/^\s*\/\/.*$/mg,'');
};
Run Code Online (Sandbox Code Playgroud)
有关详细信息,请参见此处 我试着用这种方式测试它:
console.log(console.log.getBody.getBody());
Run Code Online (Sandbox Code Playgroud)
但收到错误:TypeError: console.log.getBody is undefined.我发现可能发生这种情况是因为console.log在我实际制作原型之前定义了Function所以我在原型设计之前创建了一个空函数x并尝试调用
console.log(x.getBody.getBody());
Run Code Online (Sandbox Code Playgroud)
哪个没有问题.检查的类型console.log与typeof console.log在"功能"的结果.这是一个CodePen来试一试.所有这一切都不是一个惊喜,因为它是我所期望的,除了console.log.getBody未定义.
那么为什么原型设计Function不会影响console.log?我在Firebug 1.11.1中使用Firefox 18.0.1.
我最近console.log通过调用查看了firebugs的代码,console.log.toString()得到了这个:
function () { return Function.apply.call(x.log, x, arguments); }
Run Code Online (Sandbox Code Playgroud)
只要我明白这导致Function.apply被this引用,x.log并且参数是x和arguments.由于Function.apply它本身调用函数,因此将x.log通过this引用x和arguments作为其参数来调用它.
这引出了我的问题:有没有理由这样称呼Function.apply而不仅仅是使用Function.prototype.apply?或者换句话说,上面和之间有什么区别return x.log.apply(x, arguments)吗?
编辑:由于它是开源的,我快速查看了firebug源代码并找到了创建它的地方(consoleInjector.js,第73行):
// Construct a script string that defines a function. This function returns
// an object that wraps every 'console' method. This function will be evaluated
// in a window content sandbox and return …Run Code Online (Sandbox Code Playgroud) javascript ×3
apply ×1
asynchronous ×1
console ×1
function ×1
ireport ×1
prototyping ×1
requirejs ×1