Harigami
ログイン
12
anonymous タイトルなし
JavaScript
        class Person {
            constructor(firstName) {
                this.firstName = firstName;
            }
            myName() {
                return this.firstName;
            }
        }

        var name = new Person('fukushima');
        console.log(name.myName());

/*
*以下、エラー内容
*Uncaught TypeError: name.myName is not a function at top2.html:20
*/
  • 0
  • 1
anonymous タイトルなし
JavaScript
        class Person {
            constructor(firstName) {
                this.firstName = firstName;
            }
            myName() {
                return this.firstName;
            }
        }

        var name = new Person('fukushima');
        console.log(name.myName());

/*
以下、エラー
Uncaught TypeError: name.myName is not a function at top2.html:20
*/
  • 0
  • 0
anonymous タイトルなし
JavaScript
        class Person {
            constructor(firstName) {
                this.firstName = firstName;
            }
            myName() {
                return this.firstName;
            }
        }

        var name = new Person('fukushima');
        console.log(name.myName());





        class User {
            constructor(name, age) {
                this.name = name;
                this.age = age;
            }
            getName() {
                return this.name + this.age;
            }
        }

        //インスタンスを生成する
        var taro = new User('太郎', 32);
        console.log(taro.getName());
        document.querySelector("h1").innerHTML = taro.getName();
  • 0
  • 0
anonymous タイトルなし
JavaScript
        class Person {
            constructor(firstName) {
                this.firstName = firstName;
            }
            myName() {
                return this.firstName;
            }
        }

        var name = new Person('fukushima');
        console.log(name.myName());
  • 0
  • 0
anonymous タイトルなし
JavaScript
function removeAllFromState(state, name) {
    const options = resolveOption(name);
    if(!state[options.sourceName]) return;

    const source = state[options.sourceName];

    for(const name in options.indexes) {
        const index = options.indexes[name];
        const realName = options.prefix + '_' + name;
        if(!state[realName]) continue;
        const rootBucket = state[realName];
        const keys = index.keys;
        for(const id in source) {
            removeIndexMulti(source[id], id, rootBucket, keys);
        }
    }

    Vue.delete(state, options.sourceName);
}
  • 0
  • 0
anonymous タイトルなし
JavaScript
<template>
    <div>
            <slot/>
            <transition name="fade">
            <div class="text-xs-center" v-show="refreshing">
                <span class="progress-bg">
            <v-progress-circular
                indeterminate
                color="green"
                size="24"
                width="3"
            />
                </span>
            </div>
            </transition>
    </div>
</template>

<script lang="ts">
import { Component, Vue, Prop } from 'vue-property-decorator';
@Component({})
export default class Refreshable extends Vue {
    @Prop() refreshing?: boolean;
}

</script>

<style scoped lang="scss">
.text-xs-center {
    z-index: 2;
    vertical-align: middle;
    position: absolute;
    top: 4rem;
    left: 0;
    width: 100%;
}

.progress-bg {
    display: inline-flex;
    background-color: #fff;
    width: 50px;
    height: 50px;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    border-radius: 25px;
    box-shadow:0px 0px 10px rgba(0,0,0,0.25);
}
.fade-enter-active, .fade-leave-active {
  transition: opacity .25s;
}
.fade-enter, .fade-leave-to /* .fade-leave-active below version 2.1.8 */ {
  opacity: 0;
}
</style>

  • 0
  • 1
anonymous タイトルなし
JavaScript
function resolveOption(optname) {
    const option = opts[optname];
    if(!option.sourceName) option.sourceName = optname;
    if(!option.primary) option.primary = 'id';
    if(!option.prefix) option.prefix = optname.toLowerCase();
    return option;
}

function addValueToState(state, optname, value) {
    const options = resolveOption(optname);
    if(!state[options.sourceName]) Vue.set(state, options.sourceName, {});

    const source = state[options.sourceName];

    // Add to source
    Vue.set(source, value[options.primary], value);

    // build index
    addIndexToState(state, optname, value[options.primary]);
}

function addIndexToState(state, optname, id) {
    const options = resolveOption(optname);
    if(!state[options.sourceName]) return;

    const source = state[options.sourceName];

    if(!source[id]) return;

    const v = source[id];

    for(const name in options.indexes) {
        const index = options.indexes[name];
        const realName = options.prefix + '_' + name;
        if(!state[realName]) Vue.set(state, realName, {});
        const rootBucket = state[realName];
        const keys = index.keys;
        buildIndexMulti(v, v[options.primary], rootBucket, keys);
    }
}

function removeIndexMulti(v, id, bucket, keys, i = 0) {
    const key = v[keys[i]];
    if(keys.length-1 == i) {
        bucket[key] = bucket[key].filter(x => x != id);
    }
    else {
        removeIndexMulti(v, id, bucket[key], keys, i+1);
    }
}

function removeValueFromState(state, optname, id) {
    const options = resolveOption(optname);
    if(!state[options.sourceName]) return;

    const source = state[options.sourceName];

    if(!source[id]) return;

    // remove for each index
    removeIndexFromState(state, optname, id);

    // remove from source
    Vue.delete(source, id);
}

function removeIndexFromState(state, optname, id) {
    const options = resolveOption(optname);
    if(!state[options.sourceName]) return;

    const source = state[options.sourceName];

    if(!source[id]) return;

    const v = source[id];

    for(const name in options.indexes) {
        const index = options.indexes[name];
        const realName = options.prefix + '_' + name;
        if(!state[realName]) Vue.set(state, realName, {});
        const rootBucket = state[realName];
        const keys = index.keys;
        removeIndexMulti(v, v[options.primary], rootBucket, keys);
    }
}
  • 0
  • 1
anonymous タイトルなし
JavaScript
function addValueToState(state, options, value) {
    if(!state[options.sourceName]) return;

    const source = state[options.sourceName];

    // Add to source
    Vue.set(source, value[options.primary], value);

    // build index
    addIndexToState(state, options, value[options.primary]);
}

function addIndexToState(state, options, id) {
    if(!state[options.sourceName]) return;

    const source = state[options.sourceName];

    if(!source[id]) return;

    const v = source[id];

    for(const name in options.indexes) {
        const index = options.indexes[name];
        const realName = options.prefix + '_' + name;
        if(!state[realName]) Vue.set(state, realName, {});
        const rootBucket = state[realName];
        const keys = index.keys;
        buildIndexMulti(v, v[options.primary], rootBucket, keys);
    }
}

function removeIndexMulti(v, id, bucket, keys, i = 0) {
    const key = v[keys[i]];
    console.log(bucket);
    if(keys.length-1 == i) {
        bucket[key] = bucket[key].filter(x => x != id);
    }
    else {
        removeIndexMulti(v, id, bucket[key], keys, i+1);
    }
}

function removeValueFromState(state, options, id) {
    if(!state[options.sourceName]) return;

    const source = state[options.sourceName];

    if(!source[id]) return;

    // remove for each index
    removeIndexFromState(state, options, id);

    // remove from source
    Vue.delete(source, id);
}

function removeIndexFromState(state, options, id) {
    if(!state[options.sourceName]) return;

    const source = state[options.sourceName];

    if(!source[id]) return;

    const v = source[id];

    for(const name in options.indexes) {
        const index = options.indexes[name];
        const realName = options.prefix + '_' + name;
        if(!state[realName]) Vue.set(state, realName, {});
        const rootBucket = state[realName];
        const keys = index.keys;
        removeIndexMulti(v, v[options.primary], rootBucket, keys);
    }
}
  • 0
  • 1
anonymous タイトルなし
JavaScript
const shiftOptions: EntityOptions = {
    sourceName: 'shifts',
    primary: 'id',
    prefix: 'shift',
    indexes: {
        'idx1': { keys: [ 'branch_id', 'yearmonth', 'day' ] }
    }
}


function buildIndexMulti(v, id, bucket, keys, i = 0) {
    if(keys.length == i) {
        Vue.set(bucket, bucket.length, id);
    }
    else {
        const key = v[keys[i]]
        if(!bucket[key]) Vue.set(bucket, key, keys.length - i >= 2 ? {} : []);
        buildIndexMulti(v, id, bucket[key], keys, i+1);
    }
}

function addArrayToState(state, options, array) {
    if(!state[options.sourceName]) Vue.set(state, options.sourceName, {});

    const source = state[options.sourceName];
    const primary = options.primary;

    // build source
    for(const v of array) {
        // build source
        Vue.set(source, v[options.primary], v);
    }

    for(const name in options.indexes) {
        const index = options.indexes[name];
        const realName = options.prefix + '_' + name;
        if(!state[realName]) Vue.set(state, realName, {});
        const rootBucket = state[realName];
        const keys = index.keys;
        for(const v of array) {
            buildIndexMulti(v, v[primary], rootBucket, keys);
        }
    }
}
  • 0
  • 1
anonymous タイトルなし
JavaScript
const MyEventEmitter = function() {
    this.callbackPool = {};
}

MyEventEmitter.prototype.on = function(type, callback) {
    this.callbackPool[type] = callback;
}

MyEventEmitter.prototype.emit = function(type, arg) {
    const sliced = [];
    for(let i = 1; i < arguments.length; i++) sliced.push(arguments[i]);
    if(this.callbackPool) this.callbackPool[type].apply(undefined, sliced);
}
  • 0
  • 0
あなたもコードを投稿しませんか?
投稿する
12