William Jiang

JavaScript,PHP,Node,Perl,LAMP Web Developer – http://williamjxj.com; https://github.com/williamjxj?tab=repositories

JavaScript: some testings

JavaScript: some testings

Some of my testings of JavaScript, interesting and keep for retrieving:

function a1() { return; }
function a2() { return false; }
t=a1(); console.log(t===undefined); //true
t=a2(); console.log(t===false)		//true

//Keep in mind that the target object (first argument) will be modified, 
//and will also be returned from $.extend()
var info = { user: function(){}, pass: function(){} };
var t1 = $.extend({}, info, { type: "change", val: 123 });

var t2 = {};
$.extend(t2, info, { type: "change", val: 123 });
t1 == t2   //false
console.log(t1); //t1 and t2 are same, but not equal.

Here is a whole version of how to receive parameters from a event:

<input id='input_id' />

//2. JS parameters and calling:
var obj = {
  user: getUser(),
  pass: $.pass(),
  data: [],
  o :   {..},
  Id:  123
$('#input_id').one('click', obj, getFullList);

//3. function to process:
// The following params will accept parameters from 'click' event:
function getFullList(e) {
    var params = e.data;
    $.extend(defaults, params);

This is the way of ‘event’ pass parameters.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: