Construct your own constructor function

Source: Internet
Author: User
Tags hasownproperty

/** * @description The prototype of the extended function * @function * @obj The context of this */if (! Function.prototype.bind) {Function.prototype.bind = Function (obj) {var slice = [].slice,args = Slice.call (arguments,1), Self = This,nop = function () {},bound = function () {return self.apply (this instanceof NOP? This: (obj | | {}), Args.concat (Slice.call (arguments)))}nop.prototype = Self.prototype;bound.prototype = new NOP (); return bound}}/** * @description class constructor * @function * @public */var class = function (parent) {var Klass = function () {this.init.apply (this , arguments)}/* @init method*/klass.prototype.init = function () {}klass.fn = klass.prototype/* * @ description Inherit * @ functi On * @ public * @ Params {Object} parent Element * */IF (parent) {var subclass = function () {}subclass.prototype = parent; Klass.fn = new Subclass ();} /* * @ Description Hold Context * @ function * @ Public */klass.proxy = function (func) {var = this;return (function () {Func.ap Ply (Self,arguments)})}/* * @ Description */klass.extend = function (obj) {var extend = Obj.exTendfor (var i in obj) {if (Obj.hasownproperty (i)) {klass[i] = obj[i]}}extend && Extend (Klass)}klass.include = function (obj) {var included = Obj.includedfor (var i in obj) {if (Obj.hasownproperty (i)) {Klass.fn[i] = obj[i]}}included && included (Klass)}klass.fn.proxy = Klass.proxy;return klass}/* Create Instance button */var button = new Class (); Button.include ({init:function (element) {this.element = $ (' #aa ') This.element.click (This.proxy (This.click))}, click: function () {}})

  

Construct your own constructor function

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.