Freigeben über


WinJS.Promise object

Provides a mechanism to schedule work to be done on a value that has not yet been computed. It is an abstraction for managing interactions with asynchronous APIs.

For more information about asynchronous programming, see Asynchronous programming. For more information about promises in JavaScript, see Asynchronous programming in JavaScript.

Syntax

var aPromise = new WinJS.Promise(init, onCancel);

Members

The Promise object has these types of members:

  • Constructors
  • Events
  • Methods

Constructors

The Promise object has these constructors.

Constructor Description
Promise

A promise provides a mechanism to schedule work to be done on a value that has not yet been computed. It is a convenient abstraction for managing interactions with asynchronous APIs.

For more information about asynchronous programming, see Asynchronous programming. For more information about promises in JavaScript, see Asynchronous programming in JavaScript.

 

Events

The Promise object has these events.

Event Description
onerror

Occurs when there is an error in processing a promise.

 

Methods

The Promise object has these methods.

Method Description
addEventListener

Adds an event listener for the promise.

cancel

Attempts to cancel the fulfillment of a promised value. If the promise hasn't already been fulfilled and cancellation is supported, the promise enters the error state with a value of Error("Canceled").

dispatchEvent

Raises an event of the specified type and properties.

done

Allows you to specify the work to be done on the fulfillment of the promised value, the error handling to be performed if the promise fails to fulfill a value, and the handling of progress notifications along the way. After the handlers have finished executing, this function throws any error that would have been returned from then as a promise in the error state.

For more information about the differences between then and done, see the following topics:

removeEventListener

Removes an event listener from the control.

then

Allows you to specify the work to be done on the fulfillment of the promised value, the error handling to be performed if the promise fails to fulfill a value, and the handling of progress notifications along the way.

For more information about the differences between then and done, see the following topics:

 

Requirements

Minimum WinJS version

WinJS 2.0

Namespace

WinJS