所以当导入这样的外部模块时
import GameObjects = module("GameObjects")
Run Code Online (Sandbox Code Playgroud)
输出的JS在文件的顶部有这个:
var GameObjects = require("./GameObjects")
Run Code Online (Sandbox Code Playgroud)
但在chrome中运行时会出现此错误:>未捕获的ReferenceError:未定义require
我怎么得到这个错误?
这里已经提出了类似的问题如何在model.save()上触发成功回调?,但仍然没有回答如何从回调中触发事件.
所以这里是success我的代码中的回调,我想在其中调用addOne事件来呈现保存的注释.一切都很好,除了this.addOne(receivedItem);- 我不能this在回调中使用来触发这个事件.其他地方 - 我可以.
如何解决这个问题呢?
CommentsListView = Backbone.View.extend({
...
addOne: function (item) {
var commentView = new CommentView({
model: item
});
this.$el.append(commentView.render().el);
},
addNewComment: function (event) {
var item = {
post_id: this.$('#post_id').val(),
text: this.$('#text').val()
};
var commentItem = new CommentItem();
commentItem.save({'model':item}, {
success: function(receivedItem, response) {
this.addOne(receivedItem); // Uncaught TypeError: Object [object Window] has no method 'addOne'.
}
}, this);
}
});
Run Code Online (Sandbox Code Playgroud) 我目前用jsdoc记录我的JS文件,但是我遇到了一些麻烦.我有2个文件,file1.js并file2.js(而不是他们的真实姓名很明显).这两个文件都包含许多我在jsdoc样式中记录的函数.当我同时在两个文件上运行jsdoc时,输出是一个全局函数列表及其描述.功能实际位于何处(无论是在file1.js还是file2.js)中没有区别.有没有什么方法可以创建这种区别,以便为我的文档提供更好的结构?
我正在使用requireJS,我想从中访问一个特定的模块.不幸的是,我总是收到404消息,说明找不到该模块.
我在路径配置中包含我的js文件,如下所示:
<script src="/js/shop2/springen/vendor/require.min.js" data-main="/js/shop2/springen/app" async></script>
Run Code Online (Sandbox Code Playgroud)
我的app.js看起来像这样:
define('jquery', [], function() {
return jQuery;
});
requirejs.config({
baseUrl: '/js/shop2/springen/',
paths: {
'lodash': 'vendor/lodash.min',
'Functions': 'app/modules/functions',
'Search': 'app/modules/search',
'Comparison': 'app/modules/comparison',
'Globals': 'app/globals',
'Init': 'app/init',
...
}
});
// globals get loaded first and are available to all subordered scripts
require(['Globals', 'lodash'], function () {
$(document).ready(function() {
if ($('#comparison').length) {
require(['Comparison'], function (Comparison) {
Comparison.init();
});
} else {
require(['Init']);
}
});
});
Run Code Online (Sandbox Code Playgroud)
现在我的问题是我需要内联设置我的搜索模块,因为我必须在服务器端生成翻译并用它初始化它:
<script type="text/javascript">
$(document).ready(function(){
require(['Search'], function () {
$('#q').shopIncrementalSearch({
resultsDiv: $('#lifesearch'), …Run Code Online (Sandbox Code Playgroud) 我在这里阅读了很多关于这个主题的内容,但我仍然找不到合适的答案。我有一个类:
class A(object):
def __init__(self, first, second):
self.first = first
self.second = second
def __eq__(self, other):
return ****
def __str__(self):
return *****
def __repr__(self):
return ****
a = A("a", "b")
Run Code Online (Sandbox Code Playgroud)
例如,我如何禁止 a.first = "c" ?
为什么我收到此错误:
未捕获的TypeError:无法读取未定义的属性'scrollHeight'.
"阅读更多"按钮将我返回到页面顶部,而不是更改<div>元素的高度.我该如何解决?
这是我的代码:
function piki( $atts, $content = null ) {
{ ?>
<script type="text/javascript">
var h = jQuery('#piki')[0].scrollHeight;
jQuery('#more').click(function(e) {
e.stopPropagation();
jQuery('#piki').animate({
'height': h
})
});
jQuery(document).click(function() {
jQuery('#piki').animate({
'height': '50px'
})
})
</script>
<?php }
$url = '/?s=';
$str = '';
$output = array();
$count = 0;
foreach (explode(", ",$content) as $content) {
$count++;
$output[] = "<a href='" . $url . $content . "'>" . $content . "</a>";
if ($count == 50) {
break;
} …Run Code Online (Sandbox Code Playgroud) 我目前正在使用Java中的Cucumber和Selenium WebDriver来测试Web应用程序.我对浏览器关闭并在每个测试用例之间重新打开这一事实感到不满意.
首先,它很慢,而且对我来说没有意义.
我想要做的是在每次测试之间注销应用程序并保持浏览器打开.
我认为这条线可以完成工作,但它不能按预期工作:
driver.navigate().to("http://myurl.url");
Run Code Online (Sandbox Code Playgroud)
代替 :
driver.get("http://myurl.url");
Run Code Online (Sandbox Code Playgroud)
它会打开一个新的浏览器.我理解为什么会这样做,但我想附加到我之前的浏览器会话中.
我正在寻找一种在 JInt(C# Unity 的 javascript 解释器)中本地包含另一个 js 文件的方法。我知道我可以简单地将所有 js 文件连接到一个字符串并通过正常方式运行它。但我不想指定要加载的确切文件以及文件加载顺序。我在文件夹和子文件夹中有未定义数量的文件,我只知道哪个文件是 main.js。
是否有可能使用 nodejs 中的 require('file.js') 之类的东西,或者这完全是个坏主意?
谢谢你。
PS 这个项目打算在 Unity-JInt 下运行。
我希望为 Websockets 和 net.Sockets 分配唯一标识符,因此当接收到消息时,客户端由附加到套接字的标识符标识。
以前的研究:
对于 Websocket:
const app = express();
const server = http.createServer(app);
const wss = new WebSocket.Server({ server });
wss.on('connection', (ws) => {
ws.id = uuid.v4(); // This is the relevant line of code
ws.on('message', (msg: string) => {
...
}
});
Run Code Online (Sandbox Code Playgroud)
对于 net.Socket:
完全相同 - 根据this,需要以下内容:
var server = net.createServer();
server.on('connection', function(conn) {
conn.id = uuid.v4(); // This is the relevant line of code
conn.on('data', function(data) {
... …Run Code Online (Sandbox Code Playgroud) 我已经使用 mocha 自动化了我的 api。结构就像 -
1.对于每个 api 有一个api_namex.js文件,其中 mocha 测试驻留
每个api_namex.js文件具有一个描述()和多它()内的描述()
现在,如果我在api_namex.js文件之一(比如 api_name1.js)中使用beforeEach(),那么在运行涉及运行所有 api_namex.js 文件的整个测试套件时,所有这些文件都会调用 beforeEach()。
我应该如何让它仅针对预期的 api_namex.js 文件运行? 之前也有同样的问题。
my_areas.js文件附在下面。我在这里使用了 beforeEach()。但是在运行整个测试套件时,这个 beforeEach 在每个测试用例之前都会被调用。我只希望在此 describe() 中的每个测试用例之前使用它。
var should = require('should'),
supertest = require('supertest'),
servicesGenerator = require('../../utils/services_generator_test.js'),
responseMsg = require('../../utils/response_messages.js'),
helper = require('../../utils/helper.js'),
testData = require('../../utils/test_data.js'),
apiEndPoints = require('../../utils/api_endpoints.js');
beforeEach(function (done) {
clearMyAreas();
done();
});
describe('My Areas', function () {
it('1: All Data Valid', function …Run Code Online (Sandbox Code Playgroud) javascript ×5
jquery ×2
typescript ×2
backbone.js ×1
c# ×1
callback ×1
class ×1
immutability ×1
java ×1
jint ×1
jsdoc ×1
mocha.js ×1
node.js ×1
python ×1
requirejs ×1
scope ×1
selenium ×1
sockets ×1
websocket ×1