var script = $('<script type="text/javascript">// function </script>')
document.getElementsByTagName("head")[0].appendChild(script[0])
But in that case script will not be executed and functions will be not accessible in global namespase.
To use code in <script>
you need do as in you question
$('head').append(script);