小编alo*_*ons的帖子

Javascript:从父(超级?)函数调用子函数.

两个父函数都被子进程覆盖.孩子中有两个叫父母的两个.但是,我期望在父级别,对一个人的调用会调用孩子的方法.有一个我缺少的概念吗?

先感谢您!

http://jsfiddle.net/9mbGN/

function parent(){}

parent.prototype.one = function(){
    $('body').append("Parent: one <br/>");
}

parent.prototype.two = function(){
    this.one();
    $('body').append("Parent: two <br/>");
}


function child(){}

child.prototype = new parent();
child.prototype.constructor = child;

child.prototype.one = function(){ //should this function not be called? 
    $('body').append('Child: one <br />');
}

child.prototype.two = function(){
    $('body').append('Child: do some child stuff here and call parent: <br />');
    parent.prototype.two();    
}



var k = new child();
k.two();
Run Code Online (Sandbox Code Playgroud)

javascript inheritance prototype-programming

9
推荐指数
1
解决办法
1万
查看次数

如何为数据库实现 sequelize 向下迁移功能?

在 Sequelize.js 中,我创建了一个示例迁移文件:

module.exports = {
  up: function(migration, DataTypes, done) {
    // add altering commands here, calling 'done' when finished
    migration.createTable('Users', {
        id: {
            type: DataTypes.INTEGER, 
            primaryKey: true, 
            autoIncrement: true, 
        }, 
        createdAt: {
          type: DataTypes.DATE
        },
        updatedAt: {
          type: DataTypes.DATE
        },
        firstname: DataTypes.STRING, 
        lastname: DataTypes.STRING,
        email: DataTypes.STRING, 
        password: DataTypes.STRING,
    });
    done()
  },
  down: function(migration, DataTypes, done) {
    // add reverting commands here, calling 'done' when finished
    done()
  }
}
Run Code Online (Sandbox Code Playgroud)

有人能解释一下 up 和 down 功能的用例和可能的实现吗?

谢谢!

javascript database database-migration node.js sequelize.js

3
推荐指数
1
解决办法
5439
查看次数