sveltejs / template-webpack

Template for building basic Svelte applications with webpack
304 stars 119 forks source link

What does "window.app = app;" mean? #19

Closed frederikhors closed 4 years ago

frederikhors commented 5 years ago

The content of main.js in github.com/sveltejs/template-webpack:

import App from './App.svelte';

const app = new App({
    target: document.body,
    props: {
        name: 'world'
    }
});

window.app = app;

export default app;

The same file in github.com/sveltejs/template:

import App from './App.svelte';

const app = new App({
    target: document.body,
    props: {
        name: 'world'
    }
});

export default app;

I'm wondering what difference window.app = app; means.

Can you answer please?

coussej commented 5 years ago

From the tutorials of previous versions of svelte, I remember this was merely for easy debugging. By doing this, you can access the parent svelte component (app) from the console.

s0kil commented 5 years ago

It means that if you go to browser console, and type app or window.app it will be accessible, you could modify the app, and debug it.

antony commented 4 years ago

For usage questions, please come and chat to us