this だよ! this !!!!!!
何で、無名関数の内側で定義していたものが、その外で発動できるのか!?
そして、それが this 。
やっとわかった! 理解力ないなぁ〜>俺
(function(){ function hoge(){ alert("ok"); } this.fuga = hoge; })() fuga();
どうあがいても、<さんのレベルになれないだろうから、
もし対抗できる分野があるとしたならば、もうこれだけかもしれない!
「無意味な短さ」でどうだろう?
これは Fujillin さんも好きなはず!!
x='eight' とかするんだろうなぁ〜 と、ふっておく。(^^;
アコーディオンねたです。
<!DOCTYPE html> <title></title> <style type="text/css"> #hoge { width:500px; font-size:400px; height:500px; background:#ccc; } </style> <body> <p><input type="button" value="open/close" onclick="fuga()"></p> <div id="hoge">短</div> <script type="text/javascript"> function Accordion(a,b,c,d){ var n=document.getElementById(a),s=n.style,m=n.scrollHeight,h=d?n.clientHeight:(c=-c,0);//←カンマ演算子 s.overflow='hidden',d||(s.height=h+'px') return function(){c*=-1;(function L(){h+=c,h<0?h=0:h>m?h=m:setTimeout(L,b);s.height=h+'px'})()} } var fuga = Accordion( 'hoge', 10, 10 ); </script>
目指せ! TreeWalker
var NodeFilter = function ( a ) { if( 'undefined' !== typeof a ) this.acceptNode = a; }; NodeFilter.FILTER_ACCEPT = 1; NodeFilter.FILTER_REJECT = 2; NodeFilter.FILTER_SKIP = 3; NodeFilter.SHOW_ALL = 0xFFFFFFFF; NodeFilter.SHOW_ELEMENT = 0x00000001; NodeFilter.SHOW_ATTRIBUTE = 0x00000002; NodeFilter.SHOW_TEXT = 0x00000004; NodeFilter.SHOW_CDATA_SECTION = 0x00000008; NodeFilter.SHOW_ENTITY_REFERENCE = 0x00000010; NodeFilter.SHOW_ENTITY = 0x00000020; NodeFilter.SHOW_PROCESSING_INSTRUCTION = 0x00000040; NodeFilter.SHOW_COMMENT = 0x00000080; NodeFilter.SHOW_DOCUMENT = 0x00000100; NodeFilter.SHOW_DOCUMENT_TYPE = 0x00000200; NodeFilter.SHOW_DOCUMENT_FRAGMENT = 0x00000400; NodeFilter.SHOW_NOTATION = 0x00000800 var NodeFilterCheck = function ( bitCode, node ) { return node ? !!( ( 1 << ( node.nodeType - 1 ) ) & bitCode): false; }; //もしくは var NodeTypeCheck = (function ( ) { var table = [ 0x00000001, // ELEMENT 0x00000002, // ATTRIBUTE 0x00000004, // TEXT 0x00000008, // CDATA_SECTION 0x00000010, // ENTITY_REFERENCE 0x00000020, // ENTITY 0x00000040, // PROCESSING_INSTRUCTION 0x00000080, // COMMENT 0x00000100, // DOCUMENT 0x00000200, // DOCUMENT_TYPE 0x00000400, // DOCUMENT_FRAGMENT 0x00000800 // NOTATION }; return function ( bitCode, node ) { if( node ) { var bit = table[ node.nodeType || 0 ]; return !!( bitCode & bit ); } return false; }; })(); //それは枝の実か? var insideView = function ( parent, target ) { /*@if(@_jscript) return parent.contains( target ) && parent != target; @else@*/ return !!( parent.compareDocumentPosition( target ) & target.DOCUMENT_POSITION_CONTAINED_BY ); /*@end@*/ }; もしくは var insideView = function ( parent, target ) { while( target = target.parentNode ) if( parent == target ) return true; return false; };