1
0
mirror of https://github.com/chylex/TweetDuck.git synced 2025-04-23 21:15:49 +02:00

Add a function to code.js that checks if an object contains a nested property

This commit is contained in:
chylex 2017-05-24 18:52:55 +02:00
parent d06834617b
commit 5929067a3d
2 changed files with 23 additions and 0 deletions
Core/Bridge
Resources/Scripts

View File

@ -104,6 +104,13 @@ public void Alert(string type, string contents){
MessageBox.Show(contents, Program.BrandName+" Browser Message", MessageBoxButtons.OK, icon);
}
public void CrashDebug(string message){
#if DEBUG
Log(message);
System.Diagnostics.Debugger.Break();
#endif
}
public void Log(string data){
System.Diagnostics.Debug.WriteLine(data);
}

View File

@ -62,6 +62,22 @@
};
};
//
// Function: Returns true if an object has a specified property, otherwise returns false without throwing an error.
//
var ensurePropertyExists = function(obj, ...chain){
for(var index = 0; index < chain.length; index++){
if (!obj.hasOwnProperty(chain[index])){
$TD.crashDebug("Missing property "+chain[index]+" in chain [obj]."+chain.join("."));
return false;
}
obj = obj[chain[index]];
}
return true;
};
//
// Function: Retrieves a property of an element with a specified class.
//