javascripthtmlalloy-ui

how can I get var in the script function?


I want to get in js function value. how can i get them?

I use html and javascript and alloy-ui

I test in chrome developer console. staY.diagrambuilder or staY.Y or make function name.

<script>
 var staY = YUI().use(
    'aui-diagram-builder',

    function (Y) {
var diagrambuilder = new Y.DiagramBuilder({
            availableFields: availableFields,
            boundingBox: '#diagrambuilderBB',
            srcNode: '#diagrambuilderBB',
            fields: []
        });
console.log(diagrambuilder); //i want to access variable out of this script
});
</script>

how can i get diagrambuilder variable in chrome developer console?


Solution

  • <script>
    var diagrambuilder = null;
    var staY = YUI().use(
        'aui-diagram-builder',
    
        function (Y) {
    diagrambuilder = new Y.DiagramBuilder({
                availableFields: availableFields,
                boundingBox: '#diagrambuilderBB',
                srcNode: '#diagrambuilderBB',
                fields: []
            });
    console.log(diagrambuilder); //i want to access variable out of this script
    
    diagramInitialized();
    
    });
    
    function diagramInitialized() {
        console.log('If you are seeing this thenm diagrambuilder is available in global scope'); //it is accessible now;
        console.log(diagrambuilder); //it is accessible now;
    }
    </script>
    

    Is this what you want? @user9041996