WinJS.Binding.bind function

Links the specified binding descriptor to the specified observable source object. When the properties of the observable object specified in the bindingDescriptor change, the corresponding functions are called.

Syntax

var object = WinJS.Binding.bind(observable, bindingDescriptor);

Parameters

  • observable
    Type: Object

    The object to bind to.

  • bindingDescriptor
    Type: Object

    An object literal containing the binding declarations. The binding declarations are in the form of an anonymous object, where the properties in the object match the name of the properties in the observable object to update.

Return value

Type: Object

An object that contains a cancel method that removes all bindings associated with this bind request.

Examples

In this example, a simple observable object is created and multiple bindings are added to the object in a single call to WinJS.Binding.bind.

var observedObject = WinJS.Binding.as({
    firstName: 'Mike',
    lastName: 'Stowe'
});

WinJS.Binding.bind(observedObject,
    {
        firstName: function () { console.log("First name changed") },
        lastName: function () { console.log("Last name changed.") }
});

observedObject.firstName = "Bruce";
observedObject.lastName = "Keever";

Requirements

Minimum WinJS version

WinJS 1.0

Namespace

WinJS.Binding