Today's Question:  What does your personal desk look like?        GIVE A SHOUT

 ALL


  Ways to check existence of JavaScript object

The design of JavaScript is not so sophisticated. It's very easy for us to make mistakes if we are not very careful when using JavaScript. For example, to check the existence of JavaScript object.Now we want to check whether a global object myObj exists or not, if it doesn't exist, we declare it. The pseudo code for this is :if(myObj not exist){ declare myObj;}You may think it's very easy to write the code. In fact, it is much more difficult than we may think. Juriy Zaytsev says there are more than 50 ways to check whether a JavaScript object exist or not. Only if you are very clear about the ...

54,829 1       JAVASCRIPT OBJECT EXISTENCE


  ECMAScript 5 Objects and Properties

ECMAScript 5 is on its way. Rising from the ashes of ECMAScript 4, which got scaled way back and became ECMAScript 3.1, which was then re-named ECMAScript 5 (more details)- comes a new layer of functionality built on top of our lovable ECMAScript 3.Update: I've posted more details on ECMAScript 5 Strict Mode, JSON, and More.There are a few new APIs included in the specification but the most interesting functionality comes into play in the Object/Property code. This new code gives you the ability to dramatically affect how users will be able to interact with your objects, allowing you to provid...

1,153 0       ECMASCRIPT OBJECT PROPERTY


  An Object is not a Hash

Following my article A String is not an Error, I want to bring attention to an issue that similarly applies to JavaScript in general, but has special relevance in the Node.JS environment.The problem boils down to the usage of {} as a data-structure where the keys are supplied by untrusted user input, and the mechanisms that are normally used to assert whether a key exists.Consider the example of a simple blog created with Express. We decide to store blog posts in memory in a {}, indexed by the blog post slug. For example, this blog post would be posts['an-object-is-not-a-hash'].We start writin...

42,291 3       JAVASCRIPT OBJECT HASH NODE.JS


  JavaScript-style object literals in PHP

The object literal notation in JavaScript looks like:var fido = {name: "Fido", barks: true};or var fido = {};fido.name = "Fido";fido.barks = true;From assoc arrays to objectsIn PHP you would call that an associative array. $fido = array( 'name' => "Fido", 'barks' => true);And you can easily make it an object too:$fido = (object)$fido;echo gettype($fido); // "object"Or if you want to start with a blank object and add stuff to it:$fido = (object)array();or$fido = new StdClass();and then$fido->name = "Fido";$fido->barks = true;A little explanation maybe: objects in JavaScript are ha...

3,485 0       PHP JAVASCRIPT OBJECT FUNCTION CALL SELF VS THIS


  Don't Overload #nil?

There’s a popular post on Hacker News about writing confident code by, among other things, overloading Object#nil? and returning “null objects” instead of nil itself.DO NOT DO THIS.In Ruby, all objects (except nil itself) coerce to the boolean value true. Your object will be nil and true at the same time. Bad things will happen. Your coworkers will cry. Sad people from around the world will ask bewildering questions on your mailing list.Here’s what happens:1234567891011class NullObject def nil? true endendo = NullObject.newo.nil? #=>...

2,810 0       RUBY #NIL OVERLOAD OBJECT


  Address of a Java Object

In conventional java programming, you will never need address or location of a java object from memory. When you discuss about this in forums, the first question raised is why do you need to know the address of a java object? Its a valid question. But always, we reserve the right to experiment. Nothing is wrong in exploring uncharted areas.I thought of experimenting using a little known class from sun package. Unsafe is a class that belongs to sun.misc package. For some of you the package might be new. You need not worry about it. If you have sun’s JDK then you have this class already.W...

3,943 0       JAVA MEMORY OBJECT ADDRESS START ADDRESS