Is there a way to check againts built-in types in google apps script? I don't know how to access contructors of built-in types. So I can't use instaceof operator.
For example Profile (https://developers.google.com/apps-script/class_analytics_v3_schema_profile )
function getReportDataForProfile(profile) {
if (profile instanceof Profile) // Profile is undefined...
...
}
Also what is a litle confusing: When I get an instance of Profile (in variable profile)
profile.constructor // is undefined
After observing the output of Logger.log()
it is clear that for most built-in Google Apps objects the output of the toString()
method is the Class name:
var sheet = SpreadsheetApp.getActiveSheet()
if (typeof sheet == 'object')
{
Logger.log( String(sheet) ) // 'Sheet'
Logger.log( ''+sheet ) // 'Sheet'
Logger.log( sheet.toString() ) // 'Sheet'
Logger.log( sheet ) // 'Sheet' (the Logger object automatically calls toString() for objects)
}
So any of the above can be used to test the type of the object (except the last one example that obviously works only with the Logger
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With