Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
FogNetwork
GitHub Repository: FogNetwork/Tsunami
Path: blob/main/public/games/files/algaes-escapade/js/lib/gates/notGate.js
1039 views
1
/**
2
* Simulates a NOT gate in JavaScript. As an io object this can be used to
3
* chain together logic operators and objects
4
*
5
* @author David North
6
*/
7
function notGate()
8
{
9
notGate.prototype.constructor.call(this);
10
11
/**
12
* Overrides the addInput method of the parent so that only a single
13
* input can be added to this object. This is because the NOT gate can only
14
* operate by setting itself to a modified state of it's single input
15
*
16
* @param io input The input to add
17
*
18
* @return io
19
*/
20
this.addInput = function( input ){
21
notGate.prototype.addInput.call(this, input);
22
23
if ( this.getInputs().length > 1 )
24
{
25
throw 'You may only have one input assigned to a Not gate';
26
}
27
28
return this;
29
}
30
31
/**
32
* Overrides the setState method of the parent so that the state that this
33
* object is set to is the opposite to that provided
34
*
35
* @param boolean state The state to apply
36
*
37
* @return notGate
38
*/
39
this.setState = function( state ){
40
return notGate.prototype.setState.call(this, !state);
41
}
42
}
43
44
//Set the parent of the notGate to io
45
include_once(['lib/io.js']);
46
notGate.prototype = new io();
47
48