Passing (object.function) as a parameter

I'm building a simple drag and drop uploader using Promises however I get an Uncaught SyntaxError: Unexpected token . when I try and pass a method (object.function) as the parameter for the promise's callback functions resolve/reject. I'm looking to organize my promise callbacks as methods underneath the resolve and reject objects so in the case of upload it would be resolve.upload

传递(object.function)作为参数

我正在使用Promises构建一个简单的拖放上传器,但是我收到了Uncaught SyntaxError: Unexpected token . 当我尝试传递一个方法(object.function)作为承诺的回调函数的参数解析/拒绝。 我期待我的组织承诺回调为下面的方法resolve和reject的对象,以便在上传的情况下,这将是resolve.upload和reject.upload ,例如,如果我有发言权的用户身份验证的登入承诺,然后它会即, resolve.signin和reject.signin 。 当前的承诺模

Basic Javascript promise implementation attempt

To gain better understanding of how promises work in Javascript I decided to give it a try and code basic implementation myself. Basically I want to implement Promises Object (I call it Aaa in my code) that takes function as an argument. This function can call resolve to resolve the promise, or reject to reject it. The basic implementation and usage is below. Not sure if the second argument

基本的Javascript承诺实施尝试

为了更好地理解Javascript中承诺的工作方式,我决定试一试,并自己编写基本实现。 基本上我想实现承担对象(我称之为代码中的Aaa),它将函数作为参数。 这个函数可以调用resolve来resolve promise,或者拒绝reject它。 基本的实现和用法如下。 不知道第二个参数是否可以按照诺言规格接受,但这就是我迄今为止所获得的结果。 Aaa=function(f,pause) { console.log("ggg"); var t=this; this.f=f; this.t

How rsvp.js handles rejected promise with chain of failure callbacks

Re: https://github.com/tildeio/rsvp.js I have a function called doSomething() that does something for a little while and then returns an RSVP.Promise. Then, a chain of success and failure callbacks are registered with the returned promise (see code below). The behavior I expected was, if the promise is fulfilled, the chain of success callbacks registered with the promise will be fired, and if

rsvp.js如何处理被拒绝的承诺和失败回调链

Re:https://github.com/tildeio/rsvp.js 我有一个名为doS​​omething()的函数,稍后再执行一些操作,然后返回一个RSVP.Promise。 然后,一串成功和失败回调被注册到返回的承诺中(请参阅下面的代码)。 我期望的行为是,如果承诺得以实现,那么与承诺挂钩的成功回调链将被解雇,如果承诺被拒绝(失败),则失败回调链将被解雇。 当承诺被履行时,我会得到预期的行为,但是当我的承诺被拒绝时,我得到的行为与我预期的不

node js value return

I am a beginner to node js. Trying to call a API and result should pass to another function. Because of callback functionality second function [Task2()]is executing soon after calling the first function[Task1()], How can I handle this asynchronous behavior of node js code. I have googled for yield , but not succeeded. I have provided below sample code for your reference. Please provide your

节点js值返回

我是节点js的初学者。 试图调用API和结果应该传递给另一个函数。 由于回调函数第二个函数[Task2()]在调用第一个函数[Task1()]后不久就会执行,我该如何处理节点js代码的异步行为。 我为了收益而搜索,但没有成功。 我提供了以下示例代码供您参考。 请提供您的意见/建议。 var result=''; function Task1(){ //2 --> Executing task1 Task_Id=''; var options = { uri: 'http://url/post', //url to call me

Catching All Promise Rejections in an Async Function in JavaScript

I've ran into an issue with catching all the errors when multiple promises throw rejection errors after being awaited in an async function (javaScript - node v8.4.0). Make reference to the following javaScript: For reference, the functions timeoutOne() and timeoutTwo() simply return a native promise that resolves a value after a 1 and 2 second timeout respectively, or reject with an error

在JavaScript中的异步函数中捕获所有承诺拒绝

当多个promise在异步函数(javaScript-node v8.4.0)中等待之后抛出拒绝错误时,我遇到了捕获所有错误的问题。 引用下面的javaScript: 作为参考,函数timeoutOne()和timeoutTwo()简单地返回一个本地promise,它分别在1秒和2秒超时后解析值,或者如果将“deviousState”设置为true,则拒绝并显示错误。 let deviousState = true; async function asyncParallel() { try { let res1 = timeoutOne(); let res2 =

Calling async promises inside async promise using .join()

I´m using node/ epxress, mysql and bluebird. I´m currently doing an async database operation after the client request it. Inside the callback of the first database operation I have to perform some calculations first and afterwards doing two more database queries which are required to provide the client the correct result. My Code is separated into a Controller class, which handles the get/ p

使用.join()调用异步承诺内的异步承诺

我使用node / epxress,mysql和bluebird。 在客户端请求它之后,我正在执行异步数据库操作。 在第一个数据库操作的回调中,我必须首先执行一些计算,然后再执行两个数据库查询,这些查询是为客户端提供正确结果所必需的。 我的代码被分成一个Controller类,它处理get / post请求。 在中间是业务逻辑的服务类,它与在数据库中查询的数据库类进行对话。 我目前能够执行第一个和第二个数据库请求。 getVacation(departmentI

callback is not a function

I am trying to work with async in node js, to control the flow of execution of some functions. In the code below I have three declared functions that should print respectively 'one', 'two' and 'three', along with performing other tasks (the printing is only so that I can see what gets executed when). async.waterfall([ function(callback) { settings(); cons

回调不是一个函数

我正在尝试在节点js中使用异步,以控制某些函数的执行流程。 在下面的代码中,我有三个声明的函数,应该分别打印'one','two'和'3',并执行其他任务(打印只是为了让我看到什么时候执行)。 async.waterfall([ function(callback) { settings(); console.log("1"); callback(null, 'one'); }, function(callback) { profile(); console.log("2"); cal

nodeJS design pattern to break out of a async.waterfall or promise.then.then

This question already has an answer here: How to properly break out of a promise chain? 3 answers 通过承诺,您可以将“后续承诺”附加到您需要的执行分支: a("some data") .then(function(data) { if(data) { return "foo";//other promises won't be executed here } else { return b("some data").then(c).then(d) } }) .catch(function(err) { //log error }) .finally(function()

nodeJS设计模式打破异步流水或promise.then

这个问题在这里已经有了答案: 如何正确突破承诺链? 3个答案 通过承诺,您可以将“后续承诺”附加到您需要的执行分支: a("some data") .then(function(data) { if(data) { return "foo";//other promises won't be executed here } else { return b("some data").then(c).then(d) } }) .catch(function(err) { //log error }) .finally(function() { // do something })

async.series inside an asynchronous grunt task

I have a grunt tasks which runs asynchronously (using this.async) as I have asynchronous functions in the code. I also want few tasks to run in series so I am using async.series from async npm module. Problem is that when I reach the last callback of async.series ie function(err, result), I call a done() to inform that the asynchronous grunt task has been successfully completed, it fails someti

异步grunt任务内的async.series

我有一个异步运行的grunt任务(使用this.async),因为我在代码中具有异步功能。 我也希望有几个任务能够串行运行,所以我使用async npm模块中的async.series。 问题是,当我到达async.series的最后一个回调,即function(err,result)时,我调用done()来通知异步grunt任务已成功完成,有时会失败并且有时会传递。 我似乎无法理解它。 代码如下: grunt.registerTask('aggCompJSON', function(){ var done = this.async

Nesting node async.eachSeries

Been fighting with async module for half a day but can't get it to work properly when nesting few levels. A bit of a lengthy post due to code, but please bare with me, all code should run ok. So this works ok: var async = require('async') var myarr = ["Outer - A", "Outer - B"]; var myarr2 = ["Inner - A", "Inner - B"]; var innerComplete = true; async.eachSeries(myar

嵌套节点async.eachSeries

与异步模块一起工作了半天,但在嵌套几个级别时无法正常工作。 由于代码有点冗长的帖子,但请裸露在我身边,所有的代码应该运行良好。 所以这工作正常: var async = require('async') var myarr = ["Outer - A", "Outer - B"]; var myarr2 = ["Inner - A", "Inner - B"]; var innerComplete = true; async.eachSeries(myarr, function( item, outerCallback) { console.log('Processing ite