JS turns a function into an object without using "return" in the function expression




I've seen in a wireframe (came across it once and never again) where a developer defines a module like this:



```
core.module.define('module\_name',function(){
    //module tasks up here
    this.init = function(){
        //stuff done when module is initialized
    }
});

        

        
        
        
 (adsbygoogle = window.adsbygoogle || []).push({});
 
        

    
```

since I never saw the framework again, I tried to create my own version and copy most aspects of it - especially what the code looked like. I tried this, but I cannot name the module `init()`
  




 (adsbygoogle = window.adsbygoogle || []).push({});
 
  

because the callback is still a function, not an object. why i added`return this`
  




 (adsbygoogle = window.adsbygoogle || []).push({});
 
  





```
//my version
mycore.module.define('module\_name',function(){
    //module tasks up here
    this.init = function(){
        //stuff done when module is initialized
    }

    //i don't remember seeing this:
    return this;
});

        

        
        
        
 (adsbygoogle = window.adsbygoogle || []).push({});
 
        

    
```

in `mycore`
  




 (adsbygoogle = window.adsbygoogle || []).push({});
 
  

, I call the module this way (with `return this`
  




 (adsbygoogle = window.adsbygoogle || []).push({});
 
  

in the module definition):



```
var moduleDefinition = modules[moduleName].definition; //the callback
var module = moduleDefinition();
module.init();

        

        
        
        
 (adsbygoogle = window.adsbygoogle || []).push({});
 
        

    
```

How do I include a callback function in an object, but keep the definition way (without `return this`
  




 (adsbygoogle = window.adsbygoogle || []).push({});
 
  

in the callback definition)?
you should use:



```
var module = new moduleDefinition();

        

        
        
        
 (adsbygoogle = window.adsbygoogle || []).push({});
 
        

    
```

 and then you get the object.



  




 (adsbygoogle = window.adsbygoogle || []).push({});
 
  

Oh, and maybe you want to declare `init`
  




 (adsbygoogle = window.adsbygoogle || []).push({});
 
  

like this:



```
this.init = function() {

        

        
        
        
 (adsbygoogle = window.adsbygoogle || []).push({});
 
        

    
```

Greetings.
[image] andrei:

a quick fix is to comment the line in the "on message" tab for the function node that is troubled

when you add a module in "setup", the "import as" name is made available to the function tabs...

[image]

... so you dont need to declare it nor do you need to set/get it from co… May be the function is executed before the document is ready.
Try to use document.ready function like this:



```
$( document ).ready(function() {
    $('#machines').change(function() {
        var $selected = $(this).find(':selected');
        $('#description').html($selected.data('description'));
    }).trigger('change');
});

``` hi [@gianna.demetroulakos](/u/gianna.demetroulakos),

as mentioned by [@william.coulson](/u/william.coulson), the object reference not set to an instance of an object normally occurs when a variable is null.

run the code in the debug mode.

when the error occurs, check the variable which has a null value in locals tab.

warm regards,

ranjith u… functions prefixed with “common” are part of our example framework and not part of fmod itself. this code is added to the examples via common.cpp and common\_platform.cpp. developers would usually replace this code with their own application code. [image] bryan:

you will need to hunt through the page and find the raw html dom object.

thank you. but i guess, it’s impossible to open select widget.

callback = customjs(args=dict(select\_=select),code="""

var el = document.getelementsbyname(select\_.name)[0];

… JavaScript *itself* has nothing built in for handling query string parameters. 


Code running in a (modern) browser you can use the [`URL` object](https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams) (which is part of the APIs provided by browsers to JS):





```
var url_string = "http://www.example.com/t.html?a=1&b=3&c=m2-m3-m4-m5"; //window.location.href
var url = new URL(url_string);
var c = url.searchParams.get("c");
console.log(c);
```









For older browsers (including Internet Explorer), you can use [this polyfill](https://github.com/ungap/url-search-params) or the code from the original version of this answer that predates `URL`:


You could access `location.search`, which would give you from the `?` character on to the end of the URL or the start of the fragment identifier (#foo), whichever comes first.


Then you can parse it with this:





```
function parse_query_string(query) {
  var vars = query.split("&");
  var query_string = {};
  for (var i = 0; i < vars.length; i++) {
    var pair = vars[i].split("=");
    var key = decodeURIComponent(pair[0]);
    var value = decodeURIComponent(pair[1]);
    // If first entry with this name
    if (typeof query_string[key]  "undefined") {
      query_string[key] = decodeURIComponent(value);
      // If second entry with this name
    } else if (typeof query_string[key]  "string") {
      var arr = [query_string[key], decodeURIComponent(value)];
      query_string[key] = arr;
      // If third or later entry with this name
    } else {
      query_string[key].push(decodeURIComponent(value));
    }
  }
  return query_string;
}

var query_string = "a=1&b=3&c=m2-m3-m4-m5";
var parsed_qs = parse_query_string(query_string);
console.log(parsed_qs.c);
```




You can get the query string from the URL of the current page with:



```
var query = window.location.search.substring(1);
var qs = parse_query_string(query);

``` Reason: `s` starts at 1 and is incremented on first call, but is never reset. On seconds and subsequent calls `s` no longer starts at 1. `s` is actually unnecessary as you can use the loop counter `i` instead.



A more conventional way to do this sort of thing would be with a single function, not embedded in an object, and to control the detailed behaviour by passing parameter(s).



```
function loadGame(level){
	var values;
	switch(level){
		case 'hard':
			values: [7,8,9],
		break;
		case 'normal':
			values: [4,5,6],
		break;
		default://easy
			values: [1,2,3],
	}
	for(i=0;i<=this.values.length;i++){
		document.getElementById('n'+i).innerHTML=this.values[i];
	}
}
```


```
<div id="n0"></div>
	<div id="n1"></div>
	<div id="n2"></div>
	<input type="button" value="easy" onClick="loadGame('easy')"/>
	<input type="button" value="normal" onClick="loadGame('normal')"/>
	<input type="button" value="hard" onClick="loadGame('hard')"/>
```

**Airshow** hi

we can do that by defining a string variable in the very beginning of the process with assign activity or by defining that in variable panel in the studio at the bottom the window

but make sure that we are not assigning any value to that variable later across the workflow

if we assign later th… yes, you can using a module.

you might have seen examples of module where a only a symbol is given, e.g. from the docs:

data = mx.sym.variable('data')

fc1 = mx.sym.fullyconnected(data, name='fc1', num\_hidden=128)

act1 = mx.sym.activation(fc1, name='relu1', act\_type="relu")

fc2 = mx.sym.fullyconn… The problem is in your document.ready script:



```
$("#datepicker").datepicker();
```

This is returning an error that it is not a function. I'm not sure how the actual call should be, but check the documentation on that.