Scope question: var undefined


#1

Hi,

does anyone know why my config.host is undefined?

I thought, the var config should be part of the global scope (the file: server.js which we see below)

thanks.

import { Meteor } from 'meteor/meteor';
var QRS = require('qrs');
var config = {
	"host": '127.0.0.1',
	"useSSL": false,
	"xrfkey": 'ABCDEFG123456789',
	"authentication": "header",
	"virtualProxy": "hdr",
	"headerKey": 'hdr-usr',
	"headerValue": '2008ENT\\Qlik',
	isSecure: true
};

var qrs = new QRS(config);

Meteor.startup(() => {
    
    var qsocks = require('qsocks');

    var config = {
    	host: config.host,
    	isSecure: true
    };

#2

let me quess… because it already refers to itself? the config of the function…?


#3

Yes - the config definition in your startup function is overriding the config outside of the function. Use a different name inside your startup function, like startupConfig. If you want full details on why this is the case, read the Chapter 1: What is Scope? chapter from the You Don’t know JS: Scope & Closures book. It will take you through compiler theory and why it matters in JS.