The hasOwnProperty() method returns a boolean indicating whether the object has the specified property as its own property (as opposed to inheriting it). So it can return false, but still have that property. It just is inherited from another object and not its own.
You can use GetField() and check if it is null or BANano.UNDEFINED to see if the object actually has the property.
dim xx as BANanoObject
xx.Initialize5
xx.SetField("a", "another")
if I run
B4X:
Log(xx.HasOwnProperty("a"))
then the result WILL BE True?
Update:
tests return true - thats good enough for me!
B4X:
Dim xx As BANanoObject
xx.initialize5
xx.SetField("a", "another")
Dim b As Boolean = xx.RunMethod("hasOwnProperty", Array("a"))
Log(b)
'
xx.SetField("c", BANano.UNDEFINED)
Dim c As Boolean = xx.RunMethod("hasOwnProperty", "c")
Log(c)
BANanoObject has its own method HasOwnProperty, so no need to use RunMethod.
B4X:
xx.HasOwnProperty
EDIT: reported as returning an error sand will be fixed in the next update.
But as said, not the right method to use as it can give unexpected results on more complex objects that inherit from another. Much safer to just check if the value returned from .GetField() is null or undefined. May work in your specific case here but chances you will forget its special purpose are real in the future and think it is a bug.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.