Download presentation
Presentation is loading. Please wait.
Published byBarry Woodmancy Modified over 9 years ago
1
Ajax see 스터디 We bring e-business to your business! http://javajigi.net http://agilejava.net Javascript 작성자 : 전용우
2
2 http://agilejava.net Closure (function (something){ //do something })(something); var addMethod = function(){ if(is_ie){ return function(){attachEvent….} }else{ return function(){addEventListener..} } }();
3
3 http://agilejava.net Scope 1 function method(){ this? }; document.getElementsById(“click”).onclick=method click.addEventListener("click", method, false); click.attachEvent (“onclick", method); window click element window
4
4 http://agilejava.net Scope 2 function BigComputer(answer) { this.the_answer = answer; this.ask_question = function () { alert(this.the_answer); } function addhandler() { var deep_thought = new BigComputer(42), the_button = document.getElementById('but'); the_button.onclick = deep_thought.ask_question; } deep_thought.ask_question.apply(deep_thought);
5
5 http://agilejava.net Quiz. function buildList(list) { var result = []; for (var i = 0; i < list.length; i++) { var item = 'item' + list[i]; result.push( function() {alert(item + ' ' + list[i])} ); } return result; } function testList() { var fnlist = buildList([1,2,3]); for (var j = 0; j < fnlist.length; j++) { fnlist[j](); } }
6
6 http://agilejava.net Bubbling & Capturing. bubblingcapturing
7
7 http://agilejava.net Memory leak pattern span.onclick = function() { alert(this.innerHTML); }; span -> function ->span parentDiv.appendChild(childDiv); hostElement.appendChild(parentDiv); parentDiv.appendChild(childDiv); click.attachEvent (“onclick", method); ->unload 시 click.detachEvent("onclick", method);
8
8 http://agilejava.net Tip. var obj = if(true) return a; else return b; var obj = true?a:b ; var obj = if(a) return a; else if(b) return b else return null; var obj = a||b||c; if(a){ if(b){ if(c){ return d; } var obj = a&&b&&c&&d;
9
9 http://agilejava.net performance Tip. for(var i=0,i<object.length;i++){ document.getElementsById(“click”).onclick = object[i]; } var some = document.getElementsById(“click”).onclick ; for(var i=0,i<object.length;i++){ some = object[i]; }
10
10 http://agilejava.net performance Tip. var string; for(var i=0;i<object.length;i++){ string +=object[i]; } dom 보다는 innerHTML. eval 사용금지. if 문 보다는 switch. for 문 보다는 do while. var arr = []; for(var i=0;i<object.length;i++){ arr.push(object[i]); }
11
11 http://agilejava.net performance Tip. for(var i=0;i<object.length;i++){ //do something… } for(var i=object.length;i>0;i--){ //do something; }
12
12 http://agilejava.net 관심을 가지고 있는 것들. Offline web Offline web ReverseAjax ReverseAjax Future web Future web
13
13 http://agilejava.net 참고. Fast javascript Fast javascript Msdn fast Dhtml Msdn fast Dhtml IE memory leak pattern IE memory leak pattern Javascript scope Javascript scope Javascript closures Javascript closures Bubbling and capturing Bubbling and capturing Email:i.nevalose@gmail.com Blog:mixed.tistory.com
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.