---
title: "Jquery封装对象实例"
author: "小色帝"
date: "2016-05-14T00:48:17Z"
tags: []
categories: ["Web前端"]
slug: "jquery"
draft: false
lastmod: "2016-05-14T00:48:17Z"
id: 2298123
url: "https://wangdingxin.iteye.com/blog/2298123"
---

jQuery自定义类封装  

jQuery自定义类封装：
(function ($) {
    $.DragField = function (arg) {
        var name = "你好";     //这个是私有变量，外部无法访问
        this.testFun = function () {     //this.testFun方法，加上了this，就是公有方法了，外部可以访问。
            alert(arg.title + "," + name);
        };
    };
})(jQuery);
 
使用方法：
var a = new $.DragField({ title: "Hi" });
var b = new $.DragField({ title: "Hello" });
a.testFun();
b.testFun();