language-features

How can I find caller from inner function ?

<input type='button' id='btn' value='click' /> <script type="text/javascript"> var jObject = { bind : function(){ var o = document.getElementById('btn'); o.onclick = function(){ // How can I find caller from here ? } } }; jObject.bind(); </script> UPDATE I read some trick from here - http://www.mennovanslooten.nl/...

Can I determine who is calling a function or instantiating a class in Java?

Possible Duplicate: In Java, how do i find the caller of a method using stacktrace or reflection? I'm just curious. I was requesting that feature sometimes, but then I solved it with more code. (the calling class said its name while calling the method) ...

Language Choice for Multi-Tier/Multi-Threaded/Event-Based Container

I would like to start a new project that consists of multiple tiers, the web tier, event-driven business logic, data processing, etc. I had worked on PHP and Java-based projects for the past few years and speaking from experience, Java (and given the open source libraries to achieve scheduling, ORM, AOP, etc.) is usually a good choice - ...

Confused by Boxing. Casting -1 to Int64 throws InvalidCastException

Ok I must be overlooking something extremely simple but I am lost. Given this object val = -1; var foo = (Int32)(val); var bar = (Int64)(val); The cast to Int64 throws and InvalidCastException. I recognize this is related to some strangeness with boxing but I don't understand the reasoning. From what I understand val is boxed as ...

What is the name of a [foo, bar] = ["foo", "bar"] feature?

I need to know a correct name for this cool feature that some languages provide. FYI: In some languages it is possible to do a multiple assignments by assigning a structure of values to a structure of "variables". In the example in the question title it assigns "foo" to foo and "bar" to bar. ...

Fixed Object Id for System Objects and Small Integers in Ruby

Why do system objects like nil, true or false have a fixed object id in Ruby. Also I tried printing out the object ids of numbers, they are the same and follow an odd number sequence pattern. Any explanation for this? [nil,true,false].each { |o| print o.object_id, ' '} 4 2 0 => [nil, true, false] >> (0..50).each { |i| print i.object_id...

C 'TRUE;' Statement

I came across some code written in C that looks like this: if (file == NULL) TRUE; /* <-- What does that mean? */ I think that it is another way of saying: if (file == NULL); But am I missing something, and is there a reason to do it the first way as opposed to the second way? UPDATE: Doing some digging, TRUE is defined as s...

How unique is PHP's __autoload()?

PHP's __autoload() (documentation) is pretty interesting to me. Here's how it works: You try to use a class, like new Toast_Mitten()(footnote1) The class hasn't been loaded into memory. PHP pulls back its fist to sock you with an error. It pauses. "Wait," it says. "There's an __autoload() function defined." It runs it. In that function...

How to combine templates with enums in C++?

There are a huge feature collection in C++ programming language that supply a strict control over datatypes. Frequently one would mold his code with template system to achieve the most adequate functionality while guaranteeing within it correct type preservation and flexibility in its manipulation. Less frequently enumerations are used f...

Is Reflection the best way to determine the presense/absense of property/method on a dynamic object?

I have a number of data access methods that accept a dynamic object parameter (i.e., dynamic foo). I can't use an interface to define to type the input parameter due to existing code. I am setting properties in the data access methods, but using dynamic without checking to see if the properties/methods exist makes me nervous. So I am lo...

Collection Initialization Syntax, what for?

We just can use function like public static List<T> New<T>(params T[] items) { return new List<T>(items); } and more important it's better var list = new List<int> {1,2,3}; var list = List.New(1,2,3); So, when we really need to use it? Dictionary public static Dictionary<T, K> New<T, K>(T key, K value) { return new Dictio...

Would templates (or other technology) support the following construct?

This is kind of a follow-up from my other question. When I first heard about generics, it was before the release of Delphi 2009 (Where they introduced it first). I know it was supported in .Net before that, but I have yet to dig in that realm. Reading about generics, I learned that it allowed class to have a variable argument to it, an...