gpt4 book ai didi

javascript - 删除 CoffeeScript 匿名函数调用

转载 作者:搜寻专家 更新时间:2023-11-01 04:44:25 26 4
gpt4 key购买 nike

buildIMG = (src, resize) ->
html = '<div class="left"><div class="foods_image">'
html += '<a onclick="popitup("http://somewhere.com/test" href="javascript:void(0)">'
html += ' <img src="'+src+'" '+resize+' />'
html += '</a>'
html += '</div></div>'
html

popitup = (url) ->
newwindow=window.open(url,'name','height=640,width=640')
newwindow.focus() if window.focus
false

我目前有一个小书签,可以将 javascript 代码(上面那个)插入网站。我写了上面的 coffeescript,它生成了这个:

(function() {
var buildIMG, popitup;

buildIMG = function(src, resize) {
var html, nbsp;
html = '<div class="left"><div class="foods_image">';
html += '<a onclick="popitup(\'http://somewhere.com/test\');" href="javascript:void(0)">';
html += ' <img src="' + src + '" ' + resize + ' />';
html += '</a>';
html += '</div></div>';
return html;
};
popitup = function(url) {
var newwindow;
newwindow = window.open(url, 'name', 'height=640,width=640');
return newwindow.focus()(window.focus ? false : void 0);
};
}).call(this);

我删掉了使用 buildIMG 的函数。该函数在站点上创建一个覆盖层并显示该覆盖层中的所有图像。为每个图像调用 buildIMG 以创建 html。

问题是 onclick="popitup("http://somewhere.com/test" 部分不起作用。它是未定义的。

我做的一个解决方案是删除由 CoffeeScript 生成的这个:

(function() {

}).call(this);

我一删除它就修复了。我如何在生成的 javascript 中不将 CoffeeScript 放入这些行中?

最佳答案

CoffeeScript 允许通过 --bare 选项在没有这个安全包装器的情况下编译 JavaScript。

关于javascript - 删除 CoffeeScript 匿名函数调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10008941/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com