Accessing a script on a prefab after Instantiate

I know this has been asked before, but I think maybe either the answers I’ve found have not been for JavaScript or are for older versions of Unity because I keep getting errors that I’m not “denoting a proper type”.

Basically I want to Instantiate a prefab, then call a function that is part of the script on that prefab to set some initial variables. my function is called Init

var newPrefab:GameObject = Instantiate(prefab, spawnLocation, Quaternion.identity) as GameObject;

var initOnNewPrefab : InitScript = newPrefab.transform.GetComponent(Init);
initOnNewPrefab.Init(i,tempColor1, tempColor2);

this line

var initOnNewPrefab : InitScript = newPrefab.transform.GetComponent(Init);

was adapted from another answer I found. I found a similar one that would have written it like this

var cloneScript : NameOfScript ;
cloneScript = newPrefab.gameObject.GetComponent(NameOfScript) as NameOfScript ;
cloneScript.FunctionNameInItImTryingToDo() ;

But I get the same error here. My guess is that I need to import some sort of library to access a variable that stands for a script name. At least that’s how I read these two examples. But I don’t what the library would be.

The other thing I have tried is

var newPrefab:GameObject = Instantiate(prefab, spawnLocation, Quaternion.identity) as GameObject;

newPrefab.GetComponents(Init(i,tempColor1, tempColor2));

But this gives me “Unknown identifier:init”

Again I feel like what I’m missing is importing in my script so it’s usable.

You have

var initOnNewPrefab : InitScript = newPrefab.transform.GetComponent(Init);

But those are two different types. The type of the component must match the type of the variable. If the error says that Init is unknown, then you have no type called Init, simple as that. So you have to use the correct type.