到底什么是对象?
function Sing(){ alert(Sing.author+": "+Sing.poem) }; Sing.author="李白"; Sing.poem="床前明月光,疑是地上霜。举头望明月,低头思故乡"; Sing(); Sing.author="刘刚"; Sing.poem="hand in hand /day to day/till the end /shall we stay."; Sing();函数是特殊的对象。
但是下面的代码又让人疑惑了。 第一段代码是:
<script> var anObject={};//定义一个变量 anObject.aProperty="Property of Object";//定义属性 anObject.aMethod=function(){ alert("Method of Object") }//定义属性,属性恰好是方法 alert(anObject["aProperty"]);//"Property of Object" anObject["aMethod"]();//alert("Method of Object") for(var s in anObject){ alert(s+" is a "+typeof(anObject[s])) } //分别alert: //aProperty is a string; //aMethod is a function; </script> <script> var aFunction=function(){}; aFunction.aProperty="Property of Object"; aFunction.aMethod=function(){alert("Method of Object")}; alert(aFunction["aProperty"]); alert(aFunction["aMethod"]); for(var s in aFunction){ alert(s+" is a "+typeof(aFunction[s])) } </script>总结:对象和函数is array-alike;可以用属性名或方法名作为下表来访问; 数组:线性数据结构,有一定规律,适合进行统一的批量迭代操作; 对象:离散型数据结构,适合描述分散和个性化的东西; javascript里面的对象到底是数组,还是对象?
空闲时间看了一下软文:讲的是技术学习的路线,当然谈的更多的是规划: http://blog.csdn.net/wemedia/details.html?id=38990