introspection

How to do JavaScript object introspection?

寵の児 提交于 2019-12-17 23:14:15
问题 What to do when after all probing, a reportedly valid object return 'undefined' for any attribute probed? I use jQuery, $('selector').mouseover(function() { }); Everything returns 'undefined' for $(this) inside the function scope. The selector is a 'area' for a map tag and I'm looking for its parent attributes. 回答1: Your question is a bit vague, so maybe you can provide more details? As for finding out about an object and the values of its properties, there are many ways to do it, including

How to get the list of all attributes of a Java object using BeanUtils introspection?

五迷三道 提交于 2019-12-17 19:18:59
问题 I have method which gets a POJO as it's parameter. Now I want to programmatically get all the attributes of the POJO (because my code may not know what are all the attributes in it at run time) and need to get the values for the attributes also. Finally I'll form a string representation of the POJO. I could use ToStringBuilder, but I want build my output string in certain format specific to my requirement. Is it possible to do so in Beanutils !? If yes, any pointers to the method name? If no,

property type or class using reflection

六月ゝ 毕业季﹏ 提交于 2019-12-17 06:43:51
问题 I was wondering if it's possible to determine the class or primitive type of an Objects properties. Getting all properties names and values is pretty easy. SO answer So is there any way to get the properties class type while the property hast no value or nil value? Example Code @interface MyObject : NSObject @property (nonatomic, copy) NSString *aString; @property (nonatomic, copy) NSDate *aDate; @property NSInteger aPrimitive; @end @implementation MyObject @synthesize aString; @synthesize

property type or class using reflection

╄→尐↘猪︶ㄣ 提交于 2019-12-17 06:43:49
问题 I was wondering if it's possible to determine the class or primitive type of an Objects properties. Getting all properties names and values is pretty easy. SO answer So is there any way to get the properties class type while the property hast no value or nil value? Example Code @interface MyObject : NSObject @property (nonatomic, copy) NSString *aString; @property (nonatomic, copy) NSDate *aDate; @property NSInteger aPrimitive; @end @implementation MyObject @synthesize aString; @synthesize

ES6 classes : what about instrospection?

巧了我就是萌 提交于 2019-12-17 05:12:33
问题 In ES5, I could check the existence of a "class" (constructor function) on the window object: if (window.MyClass) { ... // do something } In ES6, according to this article, globally-declared classes are globals, but not properties of the global object ( window , on browsers): But there are now also global variables that are not properties of the global object. In global scope, the following declarations create such variables: let declarations const declarations Class declarations So if I can

Get model's fields in Django

无人久伴 提交于 2019-12-17 03:51:54
问题 Given a Django model, I'm trying to list all of its fields. I've seen some examples of doing this using the _meta model attribute, but doesn't the underscore in front of meta indicate that the _meta attribute is a private attribute and shouldn't be accessed directly? ... Because, for example, the layout of _meta could change in the future and not be a stable API? Is _meta an exception to this rule? Is it stable and ready to use or is it considered bad practice to access it? Or is there a

List all the modules that are part of a python package?

谁说我不能喝 提交于 2019-12-17 03:23:40
问题 Is there a straightforward way to find all the modules that are part of a python package? I've found this old discussion, which is not really conclusive, but I'd love to have a definite answer before I roll out my own solution based on os.listdir(). 回答1: Yes, you want something based on pkgutil or similar -- this way you can treat all packages alike regardless if they are in eggs or zips or so (where os.listdir won't help). import pkgutil # this is the package we are inspecting -- for example

Swift class introspection & generics

前提是你 提交于 2019-12-17 03:22:46
问题 I am trying to dynamically create a class instance based type using generics, however I am encountering difficulty with class introspection. Here are the questions: Is there a Swift-equivalent to Obj-C's self.class ? Is there a way to instantiate a class using the AnyClass result from NSClassFromString ? Is there a way to get AnyClass or otherwise type information strictly from a generic parameter T ? (Similar to C#'s typeof(T) syntax) 回答1: Well, for one, the Swift equivalent of [NSString

Finding what methods a Python object has

廉价感情. 提交于 2019-12-17 02:34:04
问题 Given a Python object of any kind, is there an easy way to get the list of all methods that this object has? Or, if this is not possible, is there at least an easy way to check if it has a particular method other than simply checking if an error occurs when the method is called? 回答1: For many objects , you can use this code, replacing 'object' with the object you're interested in: object_methods = [method_name for method_name in dir(object) if callable(getattr(object, method_name))] I

Iterate directories in Perl, getting introspectable objects as result

烂漫一生 提交于 2019-12-14 02:37:06
问题 I'm about to start a script that may have some file lookups and manipulation, so I thought I'd look into some packages that would assist me; mostly, I'd like the results of the iteration (or search) to be returned as objects, which would have (base)name, path, file size, uid, modification time, etc as some sort of properties. The thing is, I don't do this all that often, and tend to forget APIs; when that happens, I'd rather let the code run on an example directory, and dump all of the