几个月前我一直在玩节点,因为它是一个快速发展的项目,我想我最近拿起它时需要更新它,不知道如何阅读n,我安装了它,安装了最新版本.
一切都很好,直到我尝试使用npm,这无效,看到这个问题.
所以我需要删除n,我不知道怎么回事,而是删除了我n - {version}为每个版本安装的所有节点版本.
然后我直接从node.js网站上运行安装程序,希望它能解决我遇到的所有问题.
现在节点按预期工作,但npm被仍不能正常工作.
npm-debug.log尝试时显示的错误npm install {package}是:
ERR! Error: EISDIR, mkdir '/'
ERR! You may report this log at:
ERR! <http://github.com/isaacs/npm/issues>
ERR! or email it to:
ERR! <npm-@googlegroups.com>
ERR!
ERR! System Darwin 11.3.0
ERR! command "node" "/usr/local/bin/npm"
ERR! cwd /
ERR! node -v v0.6.15
ERR! npm -v 1.1.16
ERR! path /
ERR! code EISDIR
ERR! message EISDIR, mkdir '/'
ERR! errno {} …Run Code Online (Sandbox Code Playgroud) 编写我的第一个PHP类并遇到一个问题,以下是我的__construct方法:
public function __construct($foo,$bar) {
$this->foo = $foo;
$this->bar = $bar;
}
Run Code Online (Sandbox Code Playgroud)
这两个$foo和$bar是必需的,没有他们,该方法将无法正常工作.当对象被实例化时没有定义它们就可以了:
$var = new Class();
Run Code Online (Sandbox Code Playgroud)
因为这会引发异常(例如,Class需要2个参数,没有设置).但如果它们被设置但不是正确的类型,如下所示:
$var = new Class('33','ddd');
Run Code Online (Sandbox Code Playgroud)
我的方法将失败,因为变量的类型错误.
我应该在哪里验证这些?在构造函数或每个方法中?
我现在使用的解决方案现在有效,但我不确定它是否正确:
// $foo needs to be a string with letters only
// $bar needs to be an integer
public function __construct($foo,$bar) {
$this->foo = $foo;
$this->bar = $bar;
if(!is_numeric($bar)){
// Throw exception
}
elseif(other validation case)
etc...
}
Run Code Online (Sandbox Code Playgroud)
面向对象编程的概念对我来说是一个新手,因此非常感谢您对任何参考资料的链接.
我无法理解JavaScript中的for/in语句.
我正在使用的这本书解释如下:
for(variable in object){
statement
}
Run Code Online (Sandbox Code Playgroud)
所以举个例子:
var links = {
link1: {img: '/img/link1.jpg', w: 100 },
link2: {img: '/img/link2.jpg', w: 140 }
};
Run Code Online (Sandbox Code Playgroud)
我如何打印出所有链接?
如果我使用:
for(x in links){
document.write(x);
}
Run Code Online (Sandbox Code Playgroud)
它写出了2个属性名称(link1, link2),但是我无法理解如何访问嵌套更深层次的那些属性,我首先想到的是嵌套for/in循环,但我只是不理解语法.例如,在上面的代码中,是否x引用了属性名称?如果是这样就不会x.img获得img财产?或者是我的想法?
我很感激任何参考或链接到示例,我只是发现书中的2个代码示例并不能帮助我理解我想要的内容.
我只是在一个奇怪的"怪癖",我不确定我做错了什么.
这是代码,下面是Plunkr链接:
HTML
<!-- Shows nothing if bar === 'N', BUT shows any other letter. -->
<div ng-if="foo.bar">ng-if: {{ foo.bar }}</div>
<!-- Shows nothing is bar === 'N', BUT shows any other letter. -->
<div ng-show="foo.bar">ng-show: {{ foo.bar }}</div>
<!-- Works in all cases -->
<div ng-hide="!foo.bar">ng-hide: {{ foo.bar }}</div>
<button ng-click="foo.select('B')">Select 'B'</button>
<button ng-click="foo.select('N')">Select 'N'</button>
<button ng-click="foo.reset()">Reset</button>
Run Code Online (Sandbox Code Playgroud)
JavaScript的
angular.module('app', [])
.controller('MainController', function($scope) {
$scope.foo = {
baz: 'foo'
};
$scope.foo.select = function(item) {
$scope.foo.bar = item;
}
$scope.foo.reset = …Run Code Online (Sandbox Code Playgroud)