changing sorting layer via script

hi guys ,
would anybody tell me please that how can i change the sorting layer via script , or atleast assign sorting layer of a gameobject to another object…
and Unfortunately i write my codes with javaScript
thanx and more

Hi!
not so shure about how to do it in JS since i use C#, but you can access sorting layer via scripting trough renderer, this is working for me:

myObject.renderer.sortingLayerName = "TheSortingLayerName";

hope it helps!!!

(sorry for my english, it is not my native lang.)