TIP: Using Object.prototype.toString.apply(...);
You can use Object.prototype.toString.apply(<any JavaScript
object>); displays the value returned by primordial toString()
function even if the object's constructor function overrides the
toString() function.
For example (Array overrides the toString() function) :
alert([1,2,3].toString()); => '1,2,3'
alert(Object.prototype.toString.apply([1,2,3])); => '[object Array]' // better info than the next line
alert(typeof [1,2,3]); => 'object' // does not tell it is an Array
TIP: You can evaluate expressions like the above in the Firefox's Tools:Error Console's Evaluate text field.
Posted by sandipchitale
( Mar 31 2008, 11:07:56 PM PDT ) Permalink
Notes on JavaScript functions and objects
functions
static (or definition) context
- All functions have a property named prototype.1 The value of prototype is an object2 with a property named constructor.3 The value of constructor is the function itself.4
- All functions have a property called length which specifies the expected number of parameters as declared in function signature.5
- The value of constructor property of a function is the function Function6. That is because, the hidden super instance of a function is the value of the prototype property of the function Function.7
execution context
- While a function executes there is a special variable arguments that holds the actual arguments that were passed in when the function was invoked.
- While a function executes there is a special variable arguments which is of type Arguments which is an array-like object with a property length which gives the number of actual parameters passed in during invocation.
- The formal parameter names are really aliases of arguments object's indexed properties indexed by the ordinal number of the formal parameter.
- While a function executes there is a special variable arguments.callee holds a reference to the function object itself. Thus arguments.callee.length gives us the number of expected parameters.
- For example:
function f(p1, p2) {
// p1 is alias of arguments[0]
// p2 is alias of arguments[1]
// you can access rest of the parameters using arguments[3] thru arguments[n]
// if f was invoked like this f(10, 20, 30, 40):
// the value of p1 and arguments[0] is 10
// the value of p2 and arguments[1] is 20
// the value of arguments[2] is 30
// the value of arguments[3] is 40
// the value of arguments.length is 4 i.e. four parameters were passed in
// the value f.length is 2 - two parameters p1 and p2 declared in function declaration
// the value arguments.callee is the function f itself. This works for anonymous functions also.
// This allows writing recursive functions even in case of anonymous functions.
}
Function function
static (or definition) context
- Function being a function has a property named prototype. The value of prototype is an anonymous function function(){} with a property named constructor. The value of constructor is the function Function.
- The value of constructor property of function Function is function Function. That is because the hidden super instance of a function is the value of the prototype property of function Function.
objects such as {} or new Object()
- The constructor of an object such as {} or new Object{} of course is function Object.8
- All objects inherit properties from a hidden super instance - the prototype object. The prototype object is the same as the value of the prototype property of function which was used to create the object using the new operator. Note: objects do not have a property named prototype.
- The inherited properties behave in a copy-on-set manner.
- All objects inherit a property named constructor from their hidden super instance - the prototype object.9
Object function
static (or definition) context
- Object being a function has a property named prototype. The value of prototype is an anonymous object {} with a property named constructor.10 The value of constructor is the function Object.11
- The value of constructor property of function Object is function Function. That is because the hidden super instance of a function is the value of the prototype property of function Function.
Let us say we have code like this:function Rectangle(width, height) {
this.width = width;
this.height = height;
}
var twoByFourRectangle = new Rectabgle(2, 4);
+--------------------------------------+
inherits | +---------constructor property ----+ | +----------------------------------+
from | | | | inherits | |
| v | v from v |
function Function --- prototype property---> function(){} <----- function Object --- prototype property---> {constructor: Object}
^ ^
inherits | +---------------------------------------+ |
from | | | | inherits
| v | | from(?)
function Rectangle --- prototype property ----> {constructor: Rectangle}--+
^
inherits |
from |
|
object twoByFourRectangle --- width property ----> 2
+--- height property --> 4
1 alert("prototype" in Rectangle); => 'true'2 alert(Rectangle.prototype); => '[object Object]'
3 alert("constructor" in Rectangle.prototype); => 'true'
4 alert(Rectangle.prototype.constructor); => '[function Rectangle]'
5 alert(Rectangle.length); => '2'
6 alert(Rectangle.constructor) => 'function Function() {[native code]}'
7 alert(Rectangle.constructor.prototype) => 'function(){}'
8 alert({}.constructor); => 'function Object() {[native code]}'
9 alert("constructor" in {}); => 'true'
10 alert(Object.prototype); => '[object Object]'
11 alert(Object.prototype.constructor); => 'function Object() {[native code]}'
TIP: You can evaluate expressions like the above in the Firefox's Tools:Error Console's Evaluate text field.
Tricky huh? It was for me.
Posted by sandipchitale
( Mar 29 2008, 11:05:31 AM PDT ) Permalink
Google Talk in your Firefox sidebar
Just Create a book like this:

Set the location to:
http://talkgadget.google.com/talkgadget/client?hl=en
Make sure the Load this bookmark in the sidebar is selected.
Thats all!
Posted by sandipchitale
( Mar 15 2008, 09:23:50 AM PDT ) Permalink
Remove unused binding attribute from VisualWeb JSF pages
Prior to NetBeans IDE 6.0 release VisualWeb Pages use to generate a binding attribute in the tag for every component in the page.
For example, when a Grid Panel was dropped on Page1, the following tag was automatically generated in the Page1.jsp file:
<h:panelGrid binding="#{Page1.gridPanel1}" id="gridPanel1" style="height: 96px; left: 24px; top: 24px; position: absolute; width: 96px"/>
and the following field, getter and setter was generated in the Page1.java file:
private HtmlPanelGrid gridPanel1 = new HtmlPanelGrid();
public HtmlPanelGrid getGridPanel1() {
return gridPanel1;
}
public void setGridPanel1(HtmlPanelGrid hpg) {
this.gridPanel1 = hpg;
}
This was good if you wanted to access the gridPane1 component programmatically. Otherwise it only served to bloat the .jsp and .java files. Therefore starting with NetBeans IDE 6.1 (M1+) release we decided to not generate the binding
attribute automatically. Instead you can add and
remove the binding attribute (and the corresponding field, getter and setter) by invoking the action in the component's
pop up menu. For details, see the mini spec - On-demand binding attribute .
All this is well and good for projects developed using the NetBeans 6.1 (M1+) IDE and later. However the projects developed prior to NetBeanse 6.1 (M1+) IDE, do not benefit from this feature. That is where the new module - Remove unused binding attributes from VisualWeb JSF Pages comes for the rescue. This module installs the action - Remove unused binding attributes in the VisualWeb JSF Pages' in the projects pop up menu. When the action is invoked it shows a confirmation dialog:
Once you confirms the action, the unused binding attributes (and the corresponding field, getter and setter in the backing page bean) are removed from all the VisualWeb JSF pages in the VisualWeb project. The output window shows the processing messages. For example:
Removing unused binding attributes for components in the VisualWeb JSF Pages in the Project '/..../NetBeansProjects/WebApplication1'...
Modeling...
Modeling...Done
Processing '.../NetBeansProjects/WebApplication15/web/Page1.jsp'
:
:
:
Removed unused binding attribute for the component 'gridPanel1'.
:
:
:
Processing '.../NetBeansProjects/WebApplication15/web/Page1.jsp' Done
Processing '.../NetBeansProjects/WebApplication15/web/Page2.jsp'
:
:
Processing '.../NetBeansProjects/WebApplication15/web/Page2.jsp' Done
Processing '.../NetBeansProjects/WebApplication15/web/Page3.jsp'
:
:
Processing '.../NetBeansProjects/WebApplication15/web/Page3.jsp' Done
Removing unused binding attributes for components in the VisualWeb JSF Pages in the Project '/.../NetBeansProjects/WebApplication1'...Done
The process may take some time depending on the number of VisualWeb JSF pages in your project.
Please make sure you have backed up your project before you invoke the action. For best results invoke the action as soon as you open the project. Aftre you have processed all you projects you can remove the module by using Tools:Plugin action.
The module is available on the NetBeans 6.1 Beta Update center:
http://updates.netbeans.org/netbeans/updates/6.1/uc/beta/beta/catalog.xml.gz
You can configure the update center in the Tools:Plugins:Setting tab. NetBeans 6.1 Beta IDE is required to use this module.
Please send us your feedback here.
After processing, your project will become lean and mean, VisualWeb machine :)
Posted by sandipchitale
( Mar 12 2008, 08:54:29 AM PDT ) Permalink