Skip to content

Instantly share code, notes, and snippets.

@qcgm1978
Created December 20, 2013 09:23
Show Gist options
  • Save qcgm1978/8052387 to your computer and use it in GitHub Desktop.
Save qcgm1978/8052387 to your computer and use it in GitHub Desktop.
describe 'js, clone a function ',->
it " clones the function with '{}' acting as it's new 'this' parameter, or nothing passed works too",->
oldFunc=->
this.num=1
oldFunc.prototype.increNum=->
this.num++
func= new oldFunc()
func.increNum()
newFunc = oldFunc.bind();
a=new newFunc()
expect(a.num).toEqual 1
a.increNum()
expect(a.num).toEqual 2
<!DOCTYPE html>
<html>
<head>
<meta name="description" content="jasmine test demo" />
<link rel='stylesheet' href='http://pivotal.github.io/jasmine/lib/jasmine-1.3.1/jasmine.css'>
<script src='http://pivotal.github.io/jasmine/lib/jasmine-1.3.1/jasmine.js'></script>
<script src='http://pivotal.github.io/jasmine/lib/jasmine-1.3.1/jasmine-html.js'></script>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
<div class='version'></div>
<script type="text/javascript">
(function() {
var jasmineEnv = jasmine.getEnv();
jasmineEnv.updateInterval = 250;
/**
Create the `HTMLReporter`, which Jasmine calls to provide results of each spec and each suite. The Reporter is responsible for presenting results to the user.
*/
var htmlReporter = new jasmine.HtmlReporter();
jasmineEnv.addReporter(htmlReporter);
/**
Delegate filtering of specs to the reporter. Allows for clicking on single suites or specs in the results to only run a subset of the suite.
*/
jasmineEnv.specFilter = function(spec) {
return htmlReporter.specFilter(spec);
};
/**
Run all of the tests when the page finishes loading - and make sure to run any previous `onload` handler
### Test Results
Scroll down to see the results of all of these specs.
*/
var currentWindowOnload = window.onload;
window.onload = function() {
if (currentWindowOnload) {
currentWindowOnload();
}
document.querySelector('.version').innerHTML = jasmineEnv.versionString();
execJasmine();
};
function execJasmine() {
jasmineEnv.execute();
}
})();
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment