How do I add a texture and add a script to an object(javascript)

I have a block that when I spawn it, I want to add the texture 60xegg_strip5 and add the script NewBehaviourScript, how do I do it?

this is what I have so far

var cube : GameObject  = GameObject.CreatePrimitive(PrimitiveType.Cube);
cube.transform.position = Vector3(transform.position.x, transform.position.y, -0.1272979);
cube.transform.localScale= Vector3(2.5, 3, 0.07301977);
cube.collider.isTrigger=true;
var tex : Texture = renderer.material.GetTexture ("60xegg_strip5");
cube.renderer.material.SetTexture("tex", tex);

I think for the material, you need to add a renderer (if it doesn’t have one already) and modify the material on that.

EDIT: actually, there’s an example doing exactly this here: Unity - Scripting API: Resources.Load

var cube = Instantiate(Resources.Load("EggPrefab", GameObject));
cube.transform.position = Vector3(transform.position.x, transform.position.y, -0.1272979);

so I created a prefab of what I want, then put this inside the my spawner object but nothing is created and it gives me this error

ArgumentException: The thing you want to instantiate is null.
UnityEngine.Object.CheckNullArgument (System.Object arg, System.String message) (at E:/BuildAgent/work/71ca6fec1b41cc30/Runtime/Export/Generated/BaseClass.cs:78)
UnityEngine.Object.Instantiate (UnityEngine.Object original) (at E:/BuildAgent/work/71ca6fec1b41cc30/Runtime/Export/Generated/BaseClass.cs:64)
NewBehaviourScript 1.Update () (at Assets/NewBehaviourScript 1.js:11)