Skip to content

Instantly share code, notes, and snippets.

View mapserver2007's full-sized avatar

Ryuichi TANAKA mapserver2007

View GitHub Profile
@mapserver2007
mapserver2007 / extend.sample1.js
Created May 10, 2011 05:32
シンプルな継承パターン1
Object.prototype.mix = function() {
var c = Object.clone(this), prop, pprop, p;
for (var i = 0, len = arguments.length; i < len; i++) {
for (prop in arguments[i]) {
c[prop] = arguments[i][prop];
}
}
return c;
};
@mapserver2007
mapserver2007 / gist:967863
Created May 12, 2011 03:02
親子関係を維持したオブジェクト継承
Object.prototype.mix = function(o) {
var child = this,
parent = {},
ppropList = [];
var contains = function(ary, value) {
for (var i in ary) {
if (ary.hasOwnProperty(i) && ary[i] === value) {
return true;
}
@mapserver2007
mapserver2007 / gist:970152
Created May 13, 2011 07:39
親子関係を維持したオブジェクト継承サンプル
<html>
<head>
<script>
Object.prototype.mix = function(o) {
var child = this,
parent = {},
ppropList = [];
var contains = function(ary, value) {
@mapserver2007
mapserver2007 / gist:975811
Created May 17, 2011 02:52
プロトタイプベースOOP試作その1
Object.prototype.mix = function() {
var obj = arguments,
propList = [];
// Objectの独自拡張メソッドは追加しない
for (var pprop in Object.prototype) {
propList.push(pprop);
}
// Object拡張したプロパティに該当すればtrue
@mapserver2007
mapserver2007 / gist:975990
Created May 17, 2011 05:16
プロトタイプベースOOP試作その2.1
var Module = {};
Module.create = function(base) {
if (!!document.attachEvent) {
base.mix = function() {
var parents = arguments,
child = this;
for (var i = 0, len = parents.length; i < len; i++) {
var parent = parents[i];
for (var prop in parent) if (!child.hasOwnProperty(prop)) {
if (isReserved(prop)) throw "reserved property";
@mapserver2007
mapserver2007 / mix.js
Created May 19, 2011 09:18
プロトタイプベースOOP試作その2.2
var Telephone = Module.create({
getPhoneName: function() {
return "kurodenwa";
},
getType: function() {
return "old type";
},
telephone: function() {}
});
@mapserver2007
mapserver2007 / gist:982540
Created May 20, 2011 08:14
プロトタイプベースOOP試作その2.2のQUnit
// module define
var Telephone = Module.create({
getPhoneName: function() {
return "kurodenwa";
},
getType: function() {
return "old type";
}
});
@mapserver2007
mapserver2007 / mix.http.js
Created May 26, 2011 07:16
mix.js用HTTPモジュール(要jQuery)
var Http = Module.create({
xhr: function(url, params, opts, successCallback, errorCallback, startFunc, endFunc) {
var caller = function(f) {
if (typeof f === "function") {
f.call(this);
}
};
var start = function() { caller(startFunc); },
end = function() { caller(endFunc); },
@mapserver2007
mapserver2007 / ajax.php
Created June 6, 2011 13:14
HTTPモジュールのテスト
<?php
$name = $_POST["name"];
$result = array(
"result" => $name
);
echo json_encode($result);
?>
@mapserver2007
mapserver2007 / gist:1039781
Created June 22, 2011 09:46
エラー処理可能なJSONP
/**
* HTTP関連モジュール
*/
var Http = Module.create({
/**
* 非同期通信を実行する
* @param url 送信先URL
* @param params 送信パラメータ
* @param optArgs 通信パラメータ