Bee AntWongjorie's Blog

FE前端

BE后端

DB数据库

OPS运维

Snippet代码片段

Note笔记

I'm also on

GitHubIf you code

MailIf you talk

RSSIf you subscribe

About.meIf you recommend

Javascript设计模式 1 snippet


snippets

var CheckObject = {
    checkName: function() {},
    checkEmail: function() {},
    checkPassword: function() {}
}
var CheckObject = function() {};
CheckObject.checkName = function() {};
CheckObject.checkEmail = function() {};
CheckObject.checkPassword = function() {};
var CheckObject = function() {
  return {
    checkName: function() {},
    checkEmail: function() {},
    checkPassword: function() {}
  }
}

var a = CheckObject();
a.checkEmail();
var CheckObject = function() {
    this.checkName =  function() {},
    this.checkEmail = function() {},
    this.checkPassword =  function() {}
}

var a = new CheckObject();
a.checkEmail();
var CheckObject = function() {};
CheckObject.prototype.checkName = function() {};
CheckObject.prototype.checkEmail = function() {};
CheckObject.prototype.checkPassword = function() {};
var CheckObject = function() {};
CheckObject.prototype = {
  checkName: function() {},
  checkEmail: function() {},
  checkPassword: function() {}
}
var CheckObject = function() {};
CheckObject.prototype = {
  checkName: function() { return this; },
  checkEmail: function() { return this; },
  checkPassword: function() { return this; }
}

var a = new CheckObject();
a.checkName().checkEmail().checkPassword(); 
Function.prototype.checkEmail = function() {};

// var f = function() {};
// f.checkEmail();
// or
var f = new Function();
f.checkEmail();
Function.prototype.addMethod = function(name, fn) {
  this[name] = fn;
};

// var methods = function() {};
// or
var methods = new Function();
methods.addMethod('checkName', function() {});
methods.addMethod('checkEmail', function() {});
methods.checkName();
methods.checkEmail();
Function.prototype.addMethod = function(name, fn) {
  this[name] = fn;
  return this;
};

// var methods = function() {};
// or
var methods = new Function();
methods
  .addMethod('checkName', function() {
    return this;
  })
  .addMethod('checkEmail', function() {
    return this;
  });
methods.checkName().checkEmail();
Function.prototype.addMethod = function(name, fn) {
  this.prototype[name] = fn;
  return this;
};

// var Methods = function() {};
// or
var Methods = new Function();
Methods
  .addMethod('checkName', function() {})
  .addMethod('checkEmail', function() {});

var m = new Methods();
m.checkName();