我有下面的构造函数和SubType原型指向SuperType的实例。当我这样做时,x.isPrototypeOf(SubType.prototype)它会返回false。我很困惑,因为我已明确将其设置x为的原型SubType。有人可以告诉我为什么会这样吗?
function SuperType(){}
function SubType(){}
x = new SuperType();
SubType.prototype = x;
SubType.prototype.constructor = SubType;
console.log(x.isPrototypeOf(SubType)) // returns false
console.log(SuperType.prototype.isPrototypeOf(SubType.prototype)) // returns trueRun Code Online (Sandbox Code Playgroud)
我的React应用程序在运行于webpack-dev-server的开发环境中运行良好,但不适用于生产环境(在Apache上)。它失败,在控制台或任何地方都没有任何错误。这是我的项目的代码结构。
当我运行命令npm run dist时,将在dist目录中创建app.js和index.html文件,并将这些文件复制到apht htdocs目录中的产品环境中。现在,当我打开域时,看到空白的index.html页面,没有呈现/安装任何React组件。我可以在网络标签中看到浏览器已成功获取app.js。
package.json
{
"private": true,
"version": "0.0.1",
"description": "YOUR DESCRIPTION - Generated by generator-react-webpack",
"main": "",
"scripts": {
"clean": "rimraf dist/*",
"copy": "copyfiles -f ./src/index.html ./src/favicon.ico ./dist",
"dist": "npm run copy & webpack --env=dist",
"lint": "eslint ./src",
"posttest": "npm run lint",
"release:major": "npm version major && npm publish && git push --follow-tags",
"release:minor": "npm version minor && npm publish && git push --follow-tags",
"release:patch": "npm version patch && npm publish && git push --follow-tags", …Run Code Online (Sandbox Code Playgroud) 下面的代码只是初始化两个变量,具体取决于传递的cloudType,可以通过任何一种方法分配.在javascript中,建议使用较少的代码行,因此我喜欢第二种方法,它也会删除重复.请帮忙
方法一允许我灵活地在特定情况下添加操作,如果将来需要,因为第二种方法为我节省了大量字节也帮助我减少重复.
switch (cloudType) {
case "aws":
value = this._resetMessageDefaultValues.aws
resetText = this._messages.current.aws
break;
case "private":
value = this._resetMessageDefaultValues.private;
resetText = this._messages.current.private
break;
case "azure":
value = this._resetMessageDefaultValues.azure;
resetText = this._messages.current.azure
break;
}
Run Code Online (Sandbox Code Playgroud)
要么
value = this._resetMessageDefaultValues[cloudType];
resetText = this._messages.current[cloudType]
Run Code Online (Sandbox Code Playgroud)