public static Scriptable bind(Context cx, Scriptable scope, String id)
    {
        Scriptable firstXMLObject = null;
        Scriptable parent = scope.getParentScope();
        childScopesChecks: if (parent != null) {
            // Check for possibly nested "with" scopes first
            while (scope instanceof NativeWith) {
                Scriptable withObj = scope.getPrototype();
                if (withObj instanceof XMLObject) {
                    XMLObject xmlObject = (XMLObject)withObj;
                    if (xmlObject.has(cx, id)) {
                        return xmlObject;
                    }
                    if (firstXMLObject == null) {
                        firstXMLObject = xmlObject;
                    }
                } else {
                    if (ScriptableObject.hasProperty(withObj, id)) {
                        return withObj;
                    }
                }
                scope = parent;
                parent = parent.getParentScope();
                if (parent == null) {
                    break childScopesChecks;
                }
            }
            for (;;) {
                if (ScriptableObject.hasProperty(scope, id)) {
                    return scope;
                }
                scope = parent;
                parent = parent.getParentScope();
                if (parent == null) {
                    break childScopesChecks;
                }
            }
        }
        // scope here is top scope
        if (cx.useDynamicScope) {
            scope = checkDynamicScope(cx.topCallScope, scope);
        }
        if (ScriptableObject.hasProperty(scope, id)) {
            return scope;
        }
        // Nothing was found, but since XML objects always bind
        // return one if found
        return firstXMLObject;
    }
public static Scriptable bind ( Context cx , Scriptable scope , String id ) { Scriptable firstXMLObject = null ; Scriptable parent = scope . getParentScope ( ) ; childScopesChecks : if ( parent != null ) { while ( scope instanceof NativeWith ) { Scriptable withObj = scope . getPrototype ( ) ; if ( withObj instanceof XMLObject ) { XMLObject xmlObject = ( XMLObject ) withObj ; if ( xmlObject . has ( cx , id ) ) { return xmlObject ; } if ( firstXMLObject == null ) { firstXMLObject = xmlObject ; } } else { if ( ScriptableObject . hasProperty ( withObj , id ) ) { return withObj ; } } scope = parent ; parent = parent . getParentScope ( ) ; if ( parent == null ) { break childScopesChecks ; } } for ( ; ; ) { if ( ScriptableObject . hasProperty ( scope , id ) ) { return scope ; } scope = parent ; parent = parent . getParentScope ( ) ; if ( parent == null ) { break childScopesChecks ; } } } if ( cx . useDynamicScope ) { scope = checkDynamicScope ( cx . topCallScope , scope ) ; } if ( ScriptableObject . hasProperty ( scope , id ) ) { return scope ; } return firstXMLObject ; }
Returns the object in the scope chain that has a given property.

The order of evaluation of an assignment expression involves
evaluating the lhs to a reference, evaluating the rhs, and then
modifying the reference with the rhs value. This method is used
to 'bind' the given name to an object containing that property
so that the side effects of evaluating the rhs do not affect
which property is modified.
Typically used in conjunction with setName.

See ECMA 10.1.4