-
-
Save mannuelf/0aeb9cb7d00a34321d3b77911bda834a to your computer and use it in GitHub Desktop.
Basic Plugin Pattern Return Value return this; return this.each(); return.this.pushStack(); to maintain chainability // source http://jsbin.com/sacoba
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Basic Plugin Pattern Return Value</title> | |
<meta name="description" content="return this; return this.each(); return.this.pushStack(); to maintain chainability"> | |
<script src="https://code.jquery.com/jquery-2.1.4.js"></script> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<div id="div1">A Div</div> | |
<div id="div2">Another Div</div> | |
<script id="jsbin-javascript"> | |
(function($){ | |
$.fn.myPlugin = function() { | |
var newArray = [this[1]]; | |
console.log('First', newArray); | |
return this.pushStack(newArray); | |
}; | |
})(jQuery); | |
$(function() { | |
console.log('Second', $('div').myPlugin()); | |
console.log('Third', $('div').myPlugin().end().end()); | |
}); | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">(function($){ | |
$.fn.myPlugin = function() { | |
var newArray = [this[1]]; | |
console.log('First', newArray); | |
return this.pushStack(newArray); | |
}; | |
})(jQuery); | |
$(function() { | |
console.log('Second', $('div').myPlugin()); | |
console.log('Third', $('div').myPlugin().end().end()); | |
}); | |
</script></body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function($){ | |
$.fn.myPlugin = function() { | |
var newArray = [this[1]]; | |
console.log('First', newArray); | |
return this.pushStack(newArray); | |
}; | |
})(jQuery); | |
$(function() { | |
console.log('Second', $('div').myPlugin()); | |
console.log('Third', $('div').myPlugin().end().end()); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment