“In C++ or C#, when we’re talking about objects, we’re referring to instances of classes or structs. Objects have different properties and methods, depending on which templates (that is, classes) they are instantiated from. That’s not the case with JavaScript objects. In JavaScript, objects are just collections of name/value pairs – think of a JavaScript object as a dictionary with string keys.”
摘录来自: Manuel Kiessling. “The Node Beginner Book”
自己在 node 中尝试
> var handle = {} undefined > handle["/"] = 'aaa'; 'aaa' > handle["/start"] = 'aaa/start'; 'aaa/start' > handle["/upload"] = 'aaa/upload'; 'aaa/upload' > handle { '/': 'aaa', '/start': 'aaa/start', '/upload': 'aaa/upload' } > typeof(handle) 'object'
Leave a Reply