Javascript tips & tricks
- Coll way to join strings:
var base = 'http://acme.com',
action = 'get',
param = 'apple';
var fullUrl = [base,action,param].join('');
alert(fullUrl);
http://stackoverflow.com/questions/111102/how-do-javascript-closures-work
- Private & public members in JSON
var myWidget = function(){
//private method declaration
var myShow;
//private method body
myShow = function(){ return "I'm private!"; }
//public method declaration
this.Show = function Show() { alert(["I'm calling ->",myShow()].join('')); }
//this.Show = function Show() { alert('xx'); }
}
var coolWidget = new myWidget();
//this works
coolWidget.Show();
//this does not works. It's private member!
coolWidget.myShow();
- Use Console.Log() for quick debugging instead of annoying alert
No comments:
Post a Comment