日期:2014-05-16  浏览次数:20543 次

这段代码是类吗?

var QUERY = 'puppies';

var kittenGenerator = {

  searchOnFlickr_: 'https://secure.flickr.com/services/rest/?',


  requestKittens: function() {
    var req = new XMLHttpRequest();
    req.open("GET", this.searchOnFlickr_, true);
    req.onload = this.showPhotos_.bind(this);
    req.send(null);
  },

  showPhotos_: function (e) {
    var kittens = e.target.responseXML.querySelectorAll('photo');
    for (var i = 0; i < kittens.length; i++) {
      var img = document.createElement('img');
      img.src = this.constructKittenURL_(kittens[i]);
      img.setAttribute('alt', kittens[i].getAttribute('title'));
      document.body.appendChild(img);
    }
  },

  constructKittenURL_: function (photo) {
    return "http://farm" + photo.getAttribute("farm") +
        ".static.flickr.com/" + photo.getAttribute("server") +
        "/" + photo.getAttribute("id") +
        "_" + photo.getAttribute("secret") +
        "_s.jpg";
  }
};

// Run our kitten generation script as soon as the document's DOM is ready.
document.addEventListener('DOMContentLoaded', function () {
  kittenGenerator.requestKittens();
});


是谷歌的js代码,太长了,做了删减。能否先解释一下大概语法,然后告诉我哪里可以找到,谢谢。我在w3cschool  上面找不到这语法。

------解决方案--------------------
这个是JS,这就是几个JS方法,只不过写法有点不一样,这个是用字面量写的。kittenGenerator.方法名().这样调用就行了 。
------解决方案--------------------

function people( name , sex ){
    this.name = name 
------解决方案--------------------
 "xxx";
    this.sex = sex 
------解决方案--------------------
 "man";
};
people.prototype.say = function(){
    console.log( "hi,world!!!" );
};
var xxx = new people( "aaaa" , "women" );

4楼正解  JS是没有真正意思上的类   它是基于原型的
上面是一个  基本原型的例子。。
楼主 也可以把这个理解为“类”
------解决方案--------------------

你后缀爱是什么就是什么。

json,啊。
------解决方案--------------------
所谓的json语法   一般指的也就是面向对象的编码方式
比如

var people =&nbs