Attaching Main Camera to a GameObject

I am trying to create a function (in javascript) where if you press a button (R), the main camera will become a child of the game object (the vehicle).

#pragma strict

public var moveSpeed : float = 10f;
public var turnSpeed : float = 50f;


function Update ()
{

	if(Input.GetButtonDown("R"))
		//main camera to game object here
	
    if(Input.GetKey(KeyCode.UpArrow))
        transform.Translate(Vector3.forward * moveSpeed * Time.deltaTime);
    
    if(Input.GetKey(KeyCode.DownArrow))
        transform.Translate(-Vector3.forward * moveSpeed * Time.deltaTime);
    
    if(Input.GetKey(KeyCode.LeftArrow))
        transform.Rotate(Vector3.up, -turnSpeed * Time.deltaTime);
    
    if(Input.GetKey(KeyCode.RightArrow))
        transform.Rotate(Vector3.up, turnSpeed * Time.deltaTime);
}

Since camera is just a component, a better way to ask would be how do I attach a component to a gameObject from another object; to which your answer is found here:

How to clone or re-parent a component