12
12

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

JavaScriptの無名関数

Last updated at Posted at 2013-05-13

すぐ忘れてしまうのでめも

即時に実行する無名関数の書き方
関数内で宣言した変数は他のスクリプトに影響を与えない。
Twitterのボタン、Facebookのfb-rootなどもこの書式になっている

function_nameless.js
// 要素#hoge内にp要素を追加して「ほげほげ」とテキストを入れる
(function(d, t) {
	d.prepend('<p></p>');
	$('p', d).text(t);
})($('#hoge'), 'ほげほげ');
12
12
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
12
12

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?