Skip to content

Instantly share code, notes, and snippets.

@nickjackson
Created November 25, 2014 12:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nickjackson/b2f42be3ef09d2823748 to your computer and use it in GitHub Desktop.
Save nickjackson/b2f42be3ef09d2823748 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<script src="http://cdnjs.cloudflare.com/ajax/libs/mocha/2.0.1/mocha.js"></script>
<link rel="stylesheet" type="text/css" href="http://cdnjs.cloudflare.com/ajax/libs/mocha/2.0.1/mocha.css">
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<div id="mocha"></div>
<script id="jsbin-javascript">
function inherit(a, b) {
var fn = function() {};
fn.prototype = b.prototype;
a.prototype = new fn();
a.prototype.constructor = a;
}
function Parent(){
if (!(this instanceof Parent)) {
return new Parent();
}
}
Parent.prototype.speak = function(){
return "Hello There";
};
Parent.prototype.react = function(){
var self = this;
var c = this.constructor;
var pro = c.prototype;
var keys = Object.keys(pro);
keys.forEach(fn);
function fn(key){
var old = pro[key];
self[key] = function(one){
old.apply(self, arguments);
self.capture = one;
};
}
};
function Child(){
Parent.call(this);
}
inherit(Child, Parent);
Child.prototype.beep = function(){
console.log("Beep");
};
mocha.setup('bdd');
describe('foo', function(){
it('should set correctly', function(){
var c = new Child();
c.react();
if (c.capture) throw "shouldn't set";
c.beep('mwhahaha');
if (c.capture !== 'mwhahaha') throw "not eql";
});
});
mocha.run();
</script>
<script id="jsbin-source-html" type="text/html"><!DOCTYPE html>
<html>
<head>
<script src="//cdnjs.cloudflare.com/ajax/libs/mocha/2.0.1/mocha.js"><\/script>
<link rel="stylesheet" type="text/css" href="//cdnjs.cloudflare.com/ajax/libs/mocha/2.0.1/mocha.css">
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<div id="mocha"></div>
</body>
</html></script>
<script id="jsbin-source-javascript" type="text/javascript">function inherit(a, b) {
var fn = function() {};
fn.prototype = b.prototype;
a.prototype = new fn();
a.prototype.constructor = a;
}
function Parent(){
if (!(this instanceof Parent)) {
return new Parent();
}
}
Parent.prototype.speak = function(){
return "Hello There";
};
Parent.prototype.react = function(){
var self = this;
var c = this.constructor;
var pro = c.prototype;
var keys = Object.keys(pro);
keys.forEach(fn);
function fn(key){
var old = pro[key];
self[key] = function(one){
old.apply(self, arguments);
self.capture = one;
};
}
};
function Child(){
Parent.call(this);
}
inherit(Child, Parent);
Child.prototype.beep = function(){
console.log("Beep");
};
mocha.setup('bdd');
describe('foo', function(){
it('should set correctly', function(){
var c = new Child();
c.react();
if (c.capture) throw "shouldn't set";
c.beep('mwhahaha');
if (c.capture !== 'mwhahaha') throw "not eql";
});
});
mocha.run();
</script></body>
</html>
function inherit(a, b) {
var fn = function() {};
fn.prototype = b.prototype;
a.prototype = new fn();
a.prototype.constructor = a;
}
function Parent(){
if (!(this instanceof Parent)) {
return new Parent();
}
}
Parent.prototype.speak = function(){
return "Hello There";
};
Parent.prototype.react = function(){
var self = this;
var c = this.constructor;
var pro = c.prototype;
var keys = Object.keys(pro);
keys.forEach(fn);
function fn(key){
var old = pro[key];
self[key] = function(one){
old.apply(self, arguments);
self.capture = one;
};
}
};
function Child(){
Parent.call(this);
}
inherit(Child, Parent);
Child.prototype.beep = function(){
console.log("Beep");
};
mocha.setup('bdd');
describe('foo', function(){
it('should set correctly', function(){
var c = new Child();
c.react();
if (c.capture) throw "shouldn't set";
c.beep('mwhahaha');
if (c.capture !== 'mwhahaha') throw "not eql";
});
});
mocha.run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment