タグ

ブックマーク / wp.serpere.info (2)

  • jQuery 1.5の新機能: jQueryのサブクラスが作れるようになる | へびにっき

    jQuery 1.5 beta1 のリリースノートを見ていたら面白そうな機能があったので紹介。 jQuery.subclass() でjQueryのサブクラスを作ることができる var MyjQuery = jQuery.subclass(); 作成したサブクラスには独自のメソッドを定義することができる。定義の仕方、使い方は通常のjQueryと全く同じ。 MyjQuery.fn.writeHello = function(){ this.text('Hello World'); }; MyjQuery('p').writeHello(); 通常のjQueryメソッドはサブクラスでもそのまま使える。サブクラスを作った後に追加したメソッドも使えるので、プラグインによる拡張と組み合わせても大丈夫。 MyjQuery('div').css('border', '1px red solid').wr

    cyokodog
    cyokodog 2011/01/17
    こ、これって昔つくったやつ・・
  • jQueryでPrototype.js風のクラスを使う | へびにっき

    Prototype.js 風の Class を書きたいが、ライブラリ全体は読み込みたくない、というときのために、必要最低限のコードを抜き出してみた。要jQuery。 var Class = (function() { function subclass() {} return { create: function(parent) { function klass() { this.initialize.apply(this, arguments); } var index = 0; if(jQuery.isFunction(parent)) { index = 1; subclass.prototype = parent.prototype; klass.prototype = new subclass; } for(; index < arguments.length; ++index)

  • 1