Skip to content

Commit

Permalink
Use typeof instead of instanceof for built-in type detection, fix #27
Browse files Browse the repository at this point in the history
  • Loading branch information
y-lohse committed Sep 21, 2016
1 parent 390c400 commit 432e757
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions engine/Story.js
Original file line number Diff line number Diff line change
Expand Up @@ -880,7 +880,7 @@ export class Story extends InkObject{
}
EvaluateFunction(functionName, textOutput, args){
//match the first signature of the function
if (textOutput instanceof String === false) return this.EvaluateFunction(functionName, '', textOutput);
if (typeof textOutput !== 'string') return this.EvaluateFunction(functionName, '', textOutput);

if (functionName == null) {
throw "Function is null";
Expand Down Expand Up @@ -916,7 +916,7 @@ export class Story extends InkObject{

if (args != null) {
for (var i = 0; i < args.Length; i++) {
if (!(args[i] instanceof Number || args[i] instanceof String)) {
if (!(typeof args[i] === 'number' || typeof args[i] === 'string')) {
throw "ink arguments when calling EvaluateFunction must be int, float or string";
}

Expand Down
4 changes: 2 additions & 2 deletions engine/Value.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class AbstractValue extends InkObject{
}
static Create(val){
// Implicitly convert bools into ints
if (val instanceof Boolean){
if (typeof val === 'boolean'){
var b = !!val;
val = (b) ? 1 : 0;
}
Expand All @@ -43,7 +43,7 @@ class AbstractValue extends InkObject{
return new IntValue(val);
} else if (!isNaN(val)) {
return new FloatValue(val);
} else if (val instanceof String) {
} else if (typeof val === 'string') {
return new StringValue(val);
} else if (val instanceof Path) {
return new DivertTargetValue(val);
Expand Down

0 comments on commit 432e757

Please sign in to comment.