mootools

Update of last article about OOJS

I've updated my last article about javascript.

To instantiate objects, instead of use this very bad code :

	var s_arguments="";
	//get arguments
	for(var i=0; i<arguments.length;i++){s_arguments=s_arguments+"arguments["+i+"]"+",";}
	//put arguments in a string
	s_arguments = s_arguments.substring(0,s_arguments.length-1);
	
	//Call "constructor" with parameters
	eval("myObject."+constructor_name+"("+s_arguments+");");
	//I know, eval is evil ;-)
	
	//return instance
	return myObject;

use this :

Thanks to the "future" really good book of John Resig "Secrets of the JavaScript Ninja" (http://www.manning.com/resig/) i've found the "true way" : .apply()

			if(constructor_name!=null){ 	
				myObject[constructor_name].apply(myObject,arguments);
            }

No more eval() ;-), more beautiful code

Ugly but useful object oriented javascript notation

Hello, first of all, two things/points(?) :

  • on the right hand : i try to improve my english, so sorry for the readers (and Google Translate is my friend)
  • on the other hand : i'm not a javascript ninja

We are going to create a framework "à la MooTools".
how to have an almost "real" object-oriented notation in javascript ?
Be careful : The objective of this paper is primarily to "play" with javascript. I'm not sure my code is very clean ;-)

Simple JSON Object : create instance :


Warning: INSERT command denied to user 'kgkyojmt001'@'10.0.155.149' for table 'drp_watchdog' query: INSERT INTO drp_watchdog (uid, type, message, variables, severity, link, location, referer, hostname, timestamp) VALUES (0, 'php', '%message in %file on line %line.', 'a:4:{s:6:\"%error\";s:12:\"user warning\";s:8:\"%message\";s:372:\"INSERT command denied to user &#039;kgkyojmt001&#039;@&#039;10.0.155.149&#039; for table &#039;drp_accesslog&#039;\nquery: INSERT INTO drp_accesslog (title, path, url, hostname, uid, sid, timer, timestamp) values(&#039;mootools&#039;, &#039;taxonomy/term/108&#039;, &#039;&#039;, &#039;107.22.156.205&#039;, 0, &#039;babb6ec2a6426d3e7f2d733c48a3846e&#039;, 583, 1369322670)\";s:5:\"%file\";s:60:\"/homez.312/kgkyojmt/www/modules/statistics/statistics.module\";s:5:\"%line\";i:64;}', 3, ' in /homez.312/kgkyojmt/www/includes/database.mysql.inc on line 128

Warning: INSERT command denied to user 'kgkyojmt001'@'10.0.155.149' for table 'drp_watchdog' query: INSERT INTO drp_watchdog (uid, type, message, variables, severity, link, location, referer, hostname, timestamp) VALUES (0, 'php', '%message in %file on line %line.', 'a:4:{s:6:\"%error\";s:12:\"user warning\";s:8:\"%message\";s:904:\"UPDATE command denied to user &#039;kgkyojmt001&#039;@&#039;10.0.155.149&#039; for table &#039;drp_sessions&#039;\nquery: UPDATE drp_sessions SET uid = 0, cache = 0, hostname = &#039;107.22.156.205&#039;, session = &#039;messages|a:1:{s:5:\\&quot;error\\&quot;;a:1:{i:0;s:462:\\&quot;user warning: INSERT command denied to user &amp;#039;kgkyojmt001&amp;#039;@&amp;#039;10.0.155.149&amp;#039; for table &amp;#039;drp_accesslog&amp;#039;\\nquery: INSERT INTO drp_accesslog (title, path, url, hostname, uid, sid, timer, timest in /homez.312/kgkyojmt/www/includes/database.mysql.inc on line 128