假设我有两个模型, Topic和Post : App.Topic = DS.Model.extend({ posts: DS.hasMany('post', { async: true, inverse: 'post' }); }); App.Post = DS.Model.extend({ topic: DS.belongsTo('topic', { async: true }); }); 主题有多个post,一个postbelongsTo一个主题。 要从API中加载数据,需要进行一次初始调用(例如,获取主题…主题ID 2): GET /topics/2 在接收到GET请求的有效载荷后,串行器将links关键字附加到有效载荷上。 这有路线来加载与该主题相关的post: "topic": { "id": 2, "links": { "posts": "/topics/2/posts" } } 这个第二个请求(到/topics/2/posts )是这个post是如何加载并附加到这个主题的。 这一切工作正常,当第一次加载页面。 在页面会话期间创buildpost时发生此问题 。 虽然我可以让主题本身重新加载(通过在代表主题的模型对象上调用.reload() ),但与主题相关的Posts 不会被重新加载。 第二个API调用(获取post)从来没有做过,而第一个调用(只是得到的话题) 是做的。 如果我刷新页面,我在上一页加载创build的post将加载(但当然,如果我然后去做一些更多的post,他们将不会显示,直到下一页加载)。 寻找一个解决scheme,我碰到这个问题: 如何重新加载与链接的asynchronoushasMany关系? […]
如果我定义一个函数 inc = function(x) { return x + 1 } 并对其进行嵌套调用 inc(inc(inc(inc(inc(inc(inc(inc(inc(inc(inc(inc(inc(inc(inc(inc(inc(inc(inc(inc(inc(1))))))))))))))))))))) 这将导致值22 。 如果我修改嵌套expression式而不是使用call ,则this传入null inc.call(null, inc.call(null, inc.call(null, inc.call(null, inc.call(null, inc.call(null, inc.call(null, inc.call(null, inc.call(null, inc.call(null, inc.call(null, inc.call(null, inc.call(null, inc.call(null, inc.call(null, inc.call(null, inc.call(null, inc.call(null, inc.call(null, inc.call(null, inc.call(null, 1))))))))))))))))))))) 这也将产生值22 。 但是,在JavaScriptCore上,第二种forms似乎消耗了O (2 ^ n )内存,其中n是嵌套调用的数量。 如果我在Firefox或Chrome中尝试这种JavaScript,那么情况并非如此,因此它似乎与JavaScriptCore隔离。 我有很less的JavaScript经验(几乎没有)。 我没有感觉到各种JavaScript实现可能做出的折衷,也不知道示例代码在某些实现中是否昂贵(为闭包等提供通用支持)是合理的,而在其他实现中则是有效的。 我的问题是:这个代码固有问题吗? 是否应该改写成不同的结构? 还是代码好 – JavaScriptCore只是有一个bug? 我已经做了一些实验,重构一些临时内部调用会“截断”内存加倍行为 var […]
我有一个铬扩展挂钩到devtools。 理想情况下,我想要一个徽章,点击后,在我创build的新标签上打开devtools。 有没有办法从背景页面做到这一点?
有没有人知道在IE浏览器中分析JavaScript的工具? 可用列表: IE8 (仅限Internet Explorer 8) JavaScript分析器 YUI!
编辑:因为铬已经更新浏览器 – 这个问题是一些多余的,因为他们已经修复了一个内部的错误,这意味着这个问题不再发生。 我有一个锚定在canvas中心的圆圈animation。 圆越大,运动越不稳定。 但不仅如此,对于我来说,至less在Chrome浏览器到Firefox的情况下会更糟。 math是在这个函数中完成的: function update(deltaTime){ var centerX = canvas.width/2; var centerY = canvas.height/2; i.currentAngle = (i.currentAngle || 0) + (deltaTime/1000 * i.rotationSpeed); if(i.currentAngle>2*Math.PI){ i.currentAngle-=2*Math.PI; } ix = centerX + (i.radius*i.factor) * Math.cos(i.currentAngle); iy = centerY + (i.radius*i.factor) * Math.sin(i.currentAngle); } 这是工作示例中的代码: http://jsfiddle.net/96QDK/ Chrome输出: Firefox输出: 火狐似乎是最接近我的目标,但铬只是古怪。 为什么我会得到这样不同的结果? 我应该提一下,我问过几个人他们看到了什么,而且每个人都看到了不同的错误。
有没有办法在全球范围内捕捉所有exception,包括Promiseexception。 例: window.onerror = function myErrorHandler(errorMsg, url, lineNumber) { alert("Error occured: " + errorMsg);//or any message return false; } var myClass = function(){ } var pr = new Promise(function(resolve, react){ var myInstance = new myClass(); myInstance.undefinedFunction(); // this will throw Exception resolve(myInstance); }); pr.then(function(result){ console.log(result); }); // i know right will be this: // pr.then(function(result){ […]
我们正在重构一个遗留的Web应用程序,结果是“杀死”了很多JavaScript代码,但是由于不确定,我们害怕删除我们认为是死代码的东西。 有没有任何工具/技术来积极识别JavaScript中的死代码?
我有一组Promise.all(arrayOfPromises); 我继续承诺链。 看起来像这样 existingPromiseChain = existingPromiseChain.then(function() { var arrayOfPromises = state.routes.map(function(route){ return route.handler.promiseHandler(); }); return Promise.all(arrayOfPromises) }); existingPromiseChain = existingPromiseChain.then(function(arrayResolved) { // do stuff with my array of resolved promises, eventually ending with a res.send(); }); 我想添加一个catch语句来处理单个承诺,以防万一它出错,但是当我尝试时,Promise.all返回它find的第一个错误(忽略其余部分),然后我无法从其余的数组中的承诺(即没有错误)。 我试过做一些像.. existingPromiseChain = existingPromiseChain.then(function() { var arrayOfPromises = state.routes.map(function(route){ return route.handler.promiseHandler() .then(function(data) { return data; }) .catch(function(err) { […]
我正在使用“可拖动”指令来支持图像拖动。 但是,根据用户的angular色,我需要禁用某些用户组的图片拖动function。 我使用了下面的代码。 <!–draggable attribute is used as handle to make it draggable using jquery event–> <li ng-repeat="template in templates" draggable id="{{template._id}}" type="template" class="template-box"> <!– Images and other fields are child of "li" tag which can be dragged.–> </li> dragSupported方法在模板范围内,并返回true或false 。 我不想通过使用ng-if为dragSupported()返回的每个值创build两个大的重复<li>元素。 换句话说,我不是在寻找下面的办法来解决这个问题。 <!–draggable attribute is used as handle to make it draggable using jquery […]
如果他们是一样的,那么为什么有这样的事件呢?