javascipt 中的编程中的编程风格
?<script type="text/javascript">
??????????? //C;
??????????? function start(){
??????????? }
?????????? ?
??????????? function stop(){
?????????? ?
??????????? }
?????????? ?
??????????? //基于Class的编程风格
??????????? var Animal = function(){
?????????? ?
??????????? };
??????????? Animal.prototype.start = function(){
?????????? ?
??????????? };
??????????? Animal.prototype.stop = function(){
??????????? };
?????????? ?
??????????? //基于Joson的编程风格 这种编程风格在Jquery中应用比较广泛
??????????? var Animal = function(){
??????????? };
??????????? Animal.prototype = {
??????????????? start: function(){
??????????????? },
??????????????? stop: function(){
??????????????? }
??????????? };
?????????? ?
??????????? //基于面向对象,把类的方法声明内嵌在类的声明中,
??????????? Function.prototype.method = function(name, fun){
??????????????? this.prototype[name] = fun;
??????????? }
??????????? var Animal = function(){
??????????? };
??????????? Animal.method('start', function(){
?????????? ?
??????????? });
??????????? Animal.method('stop', function(){
?????????? ?
??????????? });
?????????? ?
??????????? //基于方法链式的编程风格
??????????? Function.prototype.method = function(name, fun){
??????????????? this.prototype[name] = fun;
??????????????? return this;
??????????? }
??????????? var Animal = function(){
??????????? };
??????????? Animal.method('start', function(){
?????????? ?
??????????? }).method('stop', function(){
?????????? ?
??????????? });
??????? </script>