Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove type global function #5942

Merged
merged 6 commits into from
Jan 15, 2024
Merged
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 11 additions & 21 deletions src/core/core.js
Original file line number Diff line number Diff line change
@@ -20,22 +20,6 @@ const common = { };
const apps = { }; // Storage for the applications using the PlayCanvas Engine
const data = { }; // Storage for exported entity data

/**
* Create look up table for types.
*
* @returns {object} A hash table containing all types in this format: { '[object Type]': 'type' }
* @private
*/
const _typeLookup = function () {
const result = { };
const names = ['Array', 'Object', 'Function', 'Date', 'RegExp', 'Float32Array'];

for (let i = 0; i < names.length; i++)
result['[object ' + names[i] + ']'] = names[i].toLowerCase();

return result;
}();

/**
* Extended typeof() function, returns the type of the object.
*
@@ -48,13 +32,19 @@ function type(obj) {
return 'null';
}

const type = typeof obj;

if (type === 'undefined' || type === 'number' || type === 'string' || type === 'boolean') {
return type;
const typeString = typeof obj;
if (['undefined', 'number', 'string', 'boolean'].includes(typeString)) {
slimbuck marked this conversation as resolved.
Show resolved Hide resolved
return typeString;
}

return _typeLookup[Object.prototype.toString.call(obj)];
return {
slimbuck marked this conversation as resolved.
Show resolved Hide resolved
'[object Array]': 'array',
'[object Object]': 'object',
'[object Function]': 'function',
'[object Date]': 'date',
'[object RegExp]': 'regexp',
'[object Float32Array]': 'float32array'
}[Object.prototype.toString.call(obj)];
}

/**