I am trying to post a Action to the Facebook Timeline using the JS API FB.api('/me/application:action_type' + '?opject_type='+document.location.href,'post', function(response) { if (!response || response.error) { alert("error"); } else { alert("success"); } }); Posting works quite well and the API returns no error. A new act
我正在尝试使用JS API将操作发布到Facebook时间轴 FB.api('/me/application:action_type' + '?opject_type='+document.location.href,'post', function(response) { if (!response || response.error) { alert("error"); } else { alert("success"); } }); 发布工作得很好,API返回没有错误。 一个新的活动出现在时间轴上,但只是在“近期活动”框中显
I have a variable in a global scope which is assigned an instance of a class like this: window.someInstance = new MyClass(); At some point later, I need to replace that variable with a new instance, but is it possible/acceptable to do that from within a method of the class itself? For example: function MyClass () { this.myClassMethod = function () { window.someInstance = new MyCl
我在全局范围内有一个变量,它被分配了一个像这样的类的实例: window.someInstance = new MyClass(); 在稍后的某个时刻,我需要用一个新实例替换该变量,但是从类本身的一个方法内部实现它可能吗? 例如: function MyClass () { this.myClassMethod = function () { window.someInstance = new MyClass(); }; } window.someInstance = new MyClass(); window.someInstance.myClassMethod.call(); 我知
This question already has an answer here: Explain the encapsulated anonymous function syntax 8 answers It is a self-executing anonymous function. The first set of parentheses contain the expressions to be executed, and the second set of parentheses executes those expressions. It is a useful construct when trying to hide variables from the parent namespace. All the code within the function
这个问题在这里已经有了答案: 解释封装的匿名函数语法8个答案 这是一个自我执行的匿名功能。 第一组圆括号包含要执行的表达式,第二组括号执行这些表达式。 当试图从父命名空间隐藏变量时,这是一个有用的构造。 函数中的所有代码都包含在函数的私有范围内,这意味着它不能从函数外部访问,从而使其真正是私有的。 看到: http://en.wikipedia.org/wiki/Closure_%28computer_science%29 http://peter.michaux.ca/
According to the docs, "Without middleware, Redux store only supports synchronous data flow". I don't understand why this is the case. Why can't the container component call the async API, and then dispatch the actions? For example, imagine a simple UI: a field and a button. When user pushes the button, the field gets populated with data from a remote server. import * as R
根据文档,“没有中间件,Redux商店只支持同步数据流”。 我不明白为什么会这样。 为什么容器组件不能调用异步API,然后dispatch这些操作? 例如,想象一个简单的用户界面:一个字段和一个按钮。 当用户按下按钮时,该字段将填充来自远程服务器的数据。 import * as React from 'react'; import * as Redux from 'redux'; import { Provider, connect } from 'react-redux'; const ActionTypes = { STARTED_UPDATING: 'S
What's the best method to get the index of an array which contains objects? Imagine this scenario: var hello = { hello: 'world', foo: 'bar' }; var qaz = { hello: 'stevie', foo: 'baz' } var myArray = []; myArray.push(hello,qaz); Now I would like to have the indexOf the object which hello property is 'stevie' which, in this example, would be 1 . I'm pretty new
获取包含对象的数组的索引的最佳方法是什么? 想象一下这个场景: var hello = { hello: 'world', foo: 'bar' }; var qaz = { hello: 'stevie', foo: 'baz' } var myArray = []; myArray.push(hello,qaz); 现在我想要有一个indexOf对象,其中hello属性是'stevie' ,在这个例子中,它将是1 。 我是JavaScript新手,我不知道是否有一个简单的方法,或者如果我应该建立自己的功能来做到这一点。 我
I would like to know what selectors are available for these data attributes that come with HTML5. Taking this piece of HTML as an example: <ul data-group="Companies"> <li data-company="Microsoft"></li> <li data-company="Google"></li> <li data-company ="Facebook"></li> </ul> Are there selectors to get: All elements with data-company="
我想知道哪些选择器可用于HTML5附带的这些数据属性。 以这段HTML为例: <ul data-group="Companies"> <li data-company="Microsoft"></li> <li data-company="Google"></li> <li data-company ="Facebook"></li> </ul> 有选择器可以得到: "Companies"下面的所有data-company="Microsoft" "Companies" 所有具有data-company!=&quo
Let's say you don't want other sites to "frame" your site in an <iframe> : <iframe src="http://example.org"></iframe> So you insert anti-framing, frame busting JavaScript into all your pages: /* break us out of any containing iframes */ if (top != self) { top.location.replace(self.location.href); } Excellent! Now you "bust" or break out of any co
假设您不希望其他网站在<iframe> “框架”您的网站: <iframe src="http://example.org"></iframe> 因此,您在所有页面中插入反框架,破坏JavaScript的框架: /* break us out of any containing iframes */ if (top != self) { top.location.replace(self.location.href); } 优秀! 现在你可以自动“破解”或者分解任何包含iframe的内容。 除了一个小问题。 事实证明, 你的框架破解代码可能被破坏 ,如
I've recently run into a rather nasty bug, wherein the code was loading a <select> dynamically via JavaScript. This dynamically loaded <select> had a pre-selected value. In IE6, we already had code to fix the selected <option> , because sometimes the <select> 's selectedIndex value would be out of sync with the selected <option> 's index attribute, as b
我最近遇到了一个相当讨厌的bug,其中代码是通过JavaScript动态加载<select> 。 这个动态加载的<select>有一个预先选定的值。 在IE6中,我们已经有了修复所选<option>代码,因为有时候<select>的selectedIndex值将与选定的<option>的index属性不同步,如下所示: field.selectedIndex = element.index; 但是,此代码无法正常工作。 即使字段的selectedIndex设置正确,错误的索引最终也会被选
I was wondering what emulators everyone uses to test your mobile development, want to make sure I'm using the most accurate emulators/simulators. I currently use the Electric Mobile Simulator from electric plum for ipad and iphone simulation as well as Opera Mini and Mobile emulators. I have downloaded the Android SDK but have trouble making this work so am very dubious about the results I
我想知道每个人用来测试移动开发的模拟器,都想确保我使用的是最精确的模拟器/模拟器。 我目前使用电动李子的电动手机模拟器,用于ipad和iphone模拟,以及Opera Mini和移动模拟器。 我已经下载了Android SDK,但无法完成这项工作,所以我非常怀疑我看到的结果。 我明白,使用真实设备来测试我的网页将会有最好的结果,但是我也喜欢在我的桌面上有一个体面的模拟器包,只是为了给我一个关于开发过程如何进展的粗略指导。
so I want to use a switch statement like this: switch (scrollLeft) { case (<1000): //do stuff break; case (>1000 && <2000): //do stuff break; } Now I know that either of those statements ( <1000 ) or ( >1000 && <2000 ) won't work (for different reasons, obviously). What I'm asking is the most efficient way to do just that. I hate using
所以我想用这样的switch语句: switch (scrollLeft) { case (<1000): //do stuff break; case (>1000 && <2000): //do stuff break; } 现在我知道这些语句( <1000 )或( >1000 && <2000 )中的任何一个都不起作用(显然由于不同的原因)。 我所要求的是最有效的方式。 我讨厌使用30条if语句,所以我宁愿使用switch语法。 有什么我可以做的吗? 当我在其他答案中查看