Examplet Center

Javascript Examplets and Examples

Select the following Topics you are interested

  1. List of all Javascript Examplets and Examples

Javascript Example - Add property to Javascript Object in "jQuery" style

Javascript Example is extracted from article "Add property to Javascript Object in "jQuery" style" from Cloudgen's Javascript Laboratory


Note for using this example:

There is no detailed explanation for this example.


Source code for the example:

<script type="text/javascript">
function closures(obj, name){
	var data;
	obj["get"+name]=function(){return data}
	obj["set"+name]=function(e){if (typeof e=="number") data=e}
}
person={};
closures(person,"Age");
person.setAge(19);
document.write("My age is "+person.getAge()+"<"+"br/>");
</script>
Output:

Copyright 2010 Cloudgen Wong