Windows Dev Center

WinJS.Binding.bind function

Applies to Windows and Windows Phone

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 supported client

Windows 8 [Windows Store apps only]

Minimum supported server

Windows Server 2012 [Windows Store apps only]

Minimum supported phone

Windows Phone 8.1

Namespace

WinJS.Binding

Library

Winjs.js

 

 

Show:
© 2015 Microsoft