策略模式下表單驗證

策略模式下表單驗證

class Validator {constructor(strategies) {this.cache = []}add(value, rules) {if (!rules instanceof Array) throw 'rules should be Array'var self = thisfor(var i = 0, rule; rule = rules[i++];) {(function(rule) {var strategyArr = rule.strategy.split(':')var errorMsg = rule.errorMsgself.cache.push(function() {var strategy = strategyArr.shift();strategyArr.unshift(value)strategyArr.push(errorMsg)return strategies[strategy].apply(null, strategyArr)})})(rule)}}start() {for (var i = 0, fn; fn = this.cache[i++]; ) {var errorMsg = fn()if (errorMsg) {return errorMsg}}}
}
復制代碼

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/391996.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/391996.shtml
英文地址,請注明出處:http://en.pswp.cn/news/391996.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

在五分鐘內學習使用Python進行類型轉換

by PALAKOLLU SRI MANIKANTA通過PALAKOLLU SRI MANIKANTA 在五分鐘內學習使用Python進行類型轉換 (Learn typecasting in Python in five minutes) 以非常詳盡的方式介紹了Python中的類型轉換和類型轉換的速成課程 (A crash course on Typecasting and Type conversion in Pyt…

Ajax post HTML 405,Web API Ajax POST向返回 405方法不允許_jquery_開發99編程知識庫

因此,我有一個像這樣的jquery ajax請求:function createLokiAccount(someurl) {var d {"Jurisdiction":17}$.ajax({type:"POST",url:"http://myserver:111/Api/V1/Customers/CreateCustomer/",data: JSON.stringify(d),c…

leetcode 480. 滑動窗口中位數(堆+滑動窗口)

中位數是有序序列最中間的那個數。如果序列的大小是偶數,則沒有最中間的數;此時中位數是最中間的兩個數的平均數。 例如: [2,3,4],中位數是 3 [2,3],中位數是 (2 3) / 2 2.5 給你一個數組 nums,有一個大…

1.0 Hadoop的介紹、搭建、環境

HADOOP背景介紹 1.1 Hadoop產生背景 HADOOP最早起源于Nutch。Nutch的設計目標是構建一個大型的全網搜索引擎,包括網頁抓取、索引、查詢等功能,但隨著抓取網頁數量的增加,遇到了嚴重的可擴展性問題——如何解決數十億網頁的存儲和索引問題。20…

如何實現多維智能監控?--AI運維的實踐探索【一】

作者丨吳樹生:騰訊高級工程師,負責SNG大數據監控平臺建設。近十年監控系統開發經驗,具有構建基于大數據平臺的海量高可用分布式監控系統研發經驗。 導語:監控數據多維化后,帶來新的應用場景。SNG的哈勃多維監控平臺在完…

.Net Web開發技術棧

有很多朋友有的因為興趣,有的因為生計而走向了.Net中,有很多朋友想學,但是又不知道怎么學,學什么,怎么系統的學,為此我以我微薄之力總結歸納寫了一篇.Net web開發技術棧,以此幫助那些想學&#…

使用Python和MetaTrader在5分鐘內開始構建您的交易策略

In one of my last posts, I showed how to create graphics using the Plotly library. To do this, we import data from MetaTrader in a ‘raw’ way without automation. Today, we will learn how to automate this process and plot a heatmap graph of the correlation…

卷積神經網絡 手勢識別_如何構建識別手語手勢的卷積神經網絡

卷積神經網絡 手勢識別by Vagdevi Kommineni通過瓦格德維科米尼(Vagdevi Kommineni) 如何構建識別手語手勢的卷積神經網絡 (How to build a convolutional neural network that recognizes sign language gestures) Sign language has been a major boon for people who are h…

spring—第一個spring程序

1.導入依賴 <dependency><groupId>org.springframework</groupId><artifactId>spring-context</artifactId><version>5.0.9.RELEASE</version></dependency>2.寫一個接口和實現 public interface dao {public void save(); }…

請對比html與css的異同,css2與css3的區別是什么?

css主要有三個版本&#xff0c;分別是css1、css2、css3。css2使用的比較多&#xff0c;因為css1的屬性比較少&#xff0c;而css3有一些老式瀏覽器并不支持&#xff0c;所以大家在開發的時候主要還是使用css2。CSS1提供有關字體、顏色、位置和文本屬性的基本信息&#xff0c;該版…

基礎 之 數組

shell中的數組 array (1 2 3) array ([1]ins1 [2]ins2 [3]ins3)array ($(命令)) # 三種定義數組&#xff0c;直接定義&#xff0c;鍵值對&#xff0c;直接用命令做數組的值。${array[*]}${array[]}${array[0]} # 輸出數組中的0位置的值&#xff0c;*和…

Linux_異常_08_本機無法訪問虛擬機web等工程

這是因為防火墻的原因&#xff0c;把響應端口開啟就行了。 # Firewall configuration written by system-config-firewall # Manual customization of this file is not recommended. *filter :INPUT ACCEPT [0:0] :FORWARD ACCEPT [0:0] :OUTPUT ACCEPT [0:0] -A INPUT -m st…

Building a WAMP Dev Environment [3/4] - Installing and Configuring PHP

Moved to http://blog.tangcs.com/2008/10/27/wamp-installing-configuring-php/轉載于:https://www.cnblogs.com/WarrenTang/archive/2008/10/27/1320069.html

ipywidgets_未來價值和Ipywidgets

ipywidgetsHow to use Ipywidgets to visualize future value with different interest rates.如何使用Ipywidgets可視化不同利率下的未來價值。 There are some calculations that even being easy becoming better with a visualization of his terms. Moreover, the sooner…

2019 css 框架_宣布CSS 2019調查狀態

2019 css 框架by Sacha Greif由Sacha Greif 宣布#StateOfCSS 2019調查 (Announcing the #StateOfCSS 2019 Survey) 了解JavaScript狀況之后&#xff0c;幫助我們確定最新CSS趨勢 (After the State of JavaScript, help us identify the latest CSS trends) I’ve been using C…

計算機主機后面輻射大,電腦的背面輻射大嗎

眾所周知&#xff0c;電子產品的輻射都比較大&#xff0c;而電腦是非常常見的電子產品&#xff0c;它也存在著一定的輻射&#xff0c;那么電腦的背面輻射大嗎?下面就一起隨佰佰安全網小編來了解一下吧。有資料顯示&#xff0c;電腦后面的輻射比前面大&#xff0c;長期近距離在…

spring— Bean標簽scope配置和生命周期配置

scope配置 singleton 默認值&#xff0c;單例的prototype 多例的request WEB 項目中&#xff0c;Spring 創建一個 Bean的對象&#xff0c;將對象存入到 request 域中session WEB 項目中&#xff0c;Spring 創建一個 Bean 的對象&#xff0c;將對象存入session 域中global sess…

裝飾器3--裝飾器作用原理

多思考&#xff0c;多記憶&#xff01;&#xff01;&#xff01; 轉載于:https://www.cnblogs.com/momo8238/p/7217345.html

用folium模塊畫地理圖_使用Folium表示您的地理空間數據

用folium模塊畫地理圖As a part of the Data Science community, Geospatial data is one of the most crucial kinds of data to work with. The applications are as simple as ‘Where’s my food delivery order right now?’ and as complex as ‘What is the most optim…

Windows下安裝Python模塊時環境配置

“Win R”打開cmd終端&#xff0c;如果直接在里面使用pip命令的時候&#xff0c;要么出現“syntax invalid”&#xff0c;要么出現&#xff1a; pip is not recognized as an internal or external command, operable program or batch file. 此時需要將C:\Python27\Scripts添加…