Posted by Patrick Steele-Idem on Monday, Jan 12th, 2015 JavaScript, Modules, Design Patterns, Node.js There's a common design pattern in the Node.js community that has been bothering me for some time since it results in less readable code. The issue relates to designing modules that export a single factory function. Let's take a look at some example code using the popular express module: var expr
Thanks to our catering sponsor Xenon we'll be offering better food than our usual pizza. Sign up quickly, as there's only limited capacity for this event. Agenda 19:00 〜 19:30 Doors open Grab a drink and catch up with your fellow Rubyists. 19:30 〜 19:55 The Pragmatic Hanami Kazuki Baba Hanami is a modern web framework for Ruby. This presentation will cover the basics of Hanami, explain its philoso
サーバサイドエンジニアの中村です。先日開催されたRubyKaigi2017に参加しました。 その中で最も興味深かったセッションである The Ruby Module Builder Pattern について自分なりの理解をまとめてみようと思います。 Moduleの問題 module内でdefine_methodを使ってメソッド定義を行ったmethodに対して、そのmoduleをextendしたclass内で該当のメソッドに対して super を呼び出すことができません。 module AdderDefiner def define_adder(*keys) define_method :+ do |other| self.class.new( *(keys.map { |key| send(key) + other.send(key) }) ) end end end class Line
RubyKaigi2017帰りの@mactkgです。これからちまちまとブログを書いていくと思いますが、よろしくお願いします。普段はRubyでRailsを書いています。 入社してから毎日Ruby(たまにiOSとSQL)を書いている日々ですが、使用しているgemのコードを眺める中でModuleの表現力に驚かされることが多々ありました。そんな中参加したRubyKaigi2017での個人的テーマは、Moduleだったのではないかと振り返って感じます(MatzのKeynoteも、Moduleの話でした)。 そんな中会場で聞いた「The Ruby Module Builder Pattern」というトークが面白かったのですが、最近使ったShrineという画像アップロードのgemの実装とつながり、ビビっと来ましたので記事にします。まずはModule Builder Patternから…。 Module
There’s an interesting pattern I’ve discovered recently in Ruby that is very powerful, yet apparently not widely known or appreciated.1 I call this pattern the Module Builder Pattern. I’ve used it heavily in designing Mobility, a pluggable translation framework I released a couple months ago, and it served me so well I thought I should share what I’ve learned. At its core, the Module Builder is an
It declares a function, which then calls itself immediately. These are also known as Immediately-Invoked-Function-Expressions, in which the function creates new scope and creates “privacy”. JavaScript doesn’t have privacy, but creating new scope emulates this when we wrap all our function logic inside them. The idea then is to return only the parts we need, leaving the other code out of the global
JSDoc and the Revealing Module Pattern Posted on March 25, 2014 by Carsten Zimmermann javascript module jsdoc Before the grand v1.0.0 of an internal asset pipeline gem with lots of extracted javascript from our various Rails apps, I wanted to see what our API documentation looked like in colourful HTML. Much to my surprise, JSDoc didn’t show a thing when I ran it over our .js files: We use the Rev
The Module Pattern is the use of closures to create, in essence, private functions that are only accessible by other functions created within that closure. Functions can be attached to an object and returned outside of that function call. This establishes a public API and only the functions defined within that public API will have access to those hidden functions. The YUI blog documents this well
Javascriptの記述方法としては、functionを書き連ねて、必要に応じて呼び出すことが多いんじゃないかと思う。だが、それだと雑然としたコードになって、「とりあえず書いてみました」的な印象となってしまう。 このログでもしばしば取り上げてきたが、YUI Blogにモジュール・パターン(module pattern)という書き方が紹介されている。具体的には、以下のようなコードになる。 ObjectName = function() { var private_variable1; var private_function1 = function(){ } return{ public_variable1: public_function1: function() { } } }(); この場合、 ObjectName.public_variable1; ObjectName.publi
Again with the Module Pattern – reveal something to the world Not too long ago I was raving about the beauty of the Module Pattern in JavaScript and the annoyance I felt with it when it comes to repetition of long namespaces when calling or reading public methods and properties from other public methods and properties. To recap, the “classic” Module Pattern means you define a variable as an anonym
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く