首页 > Web开发 > 详细

js常用几种类方法实现

时间:2016-02-02 18:57:58      阅读:256      评论:0      收藏:0      [点我收藏+]

js定义类方法的常用几种定义

1 定义方法,方法中包含实现

function createCORSRequest() {
    var xhr = new XMLHttpRequest();
    
    xhr.onload = function () {
        console.log(‘Response : ‘ + xdr.responseText);
    };
    
    xhr.onerror = function () {
        console.log(‘Failed to retrieve data!‘);
    };

    return xhr;
}

 调用

var xhr = createCORSRequest();
 xhr.open(GET, https://www.hsbc.com.hk/zh-cn/index.html, true);
 xhr.send(null);

2 定义对象,用对象扩展方法

var img = new Image();
img.onload = function () {
    console.debug(‘request successfully.‘);
};

img.onerror = function () {
    console.debug(‘request failed‘);
}

img.src = ‘http://www.somesite.com/test?username=AndyLuo&ad=wealth‘;

3 定义类,用类实现方法

var Sign = {
    _businessId: 0,
    init: function () {
    },
    BindSignEvent: function (){
    
  } }

js常用几种类方法实现

原文:http://www.cnblogs.com/f23wangj/p/5178281.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!