What Javascript types can have properties? -


What is the best way to determine whether X can have an asset? Can I just do

if (x example object)

Is it enough to make sure that there can be properties in X or Do I need to check anything else? I know that there are no qualities in the ancient properties, but is there anything else? I am checking various types:

  var a = false; A.foo = "bar"; Console.log (a ["foo"]); // logs undefined var b = "b"; Bfu = "bar"; Console.log (b ["foo"]); // logs undefined var c = new array (1,2,3); C.foo = "bar"; Console.log (c ["foo"]); // log time var d = new object (); D.foo = "bar"; Console.log (d ["foo"]); // log time var e = new regx (""); E.foo = "foo"; Console.log (d ["bar"]); // log time var f = new number (1); F.foo = "bar"; Console.log (f ["foo"]); // log time var g = function () {}; G. Fu = "bar"; Console.log (g ["foo"]); // log bar   

etc.

Yes, that's quite a lot. Note: You can also accept string properties, which you are not checking:

  var a = new string ("hello"); A.foo = "bar";   

But since the origin of the string == true you should be OK.

For fun, try it (this works, because / x / installation object == true ):

  var x = / Hello /; X.foo = "bar";   

Another note: Your example check will catch it, but I want you to know that normal one javascript function object , a closure (function () {}) () is not required a object , but it does not < may be

-tjw

Comments