原始类型(Number,String等)按值传递,但是对象是未知的,因为它们可以是值传递(如果我们认为持有对象的变量实际上是对象的引用)并且通过引用传递(当我们认为对象的变量保存对象本身时).
虽然最后并不重要,但我想知道提交传递约定的参数的正确方法是什么.是否有JavaScript规范的摘录,它定义了与此相关的语义?
该API参考范围页面说:
范围可以从父范围继承.
该开发者指南范围页说:
范围(原型)从其父范围继承属性.
那么,子范围是否始终从其父范围继承原型?有例外吗?当它继承时,它是否总是正常的JavaScript原型继承?
javascript inheritance prototype prototypal-inheritance angularjs
我有两个Angular控制器:
function Ctrl1($scope) {
$scope.prop1 = "First";
}
function Ctrl2($scope) {
$scope.prop2 = "Second";
$scope.both = Ctrl1.prop1 + $scope.prop2; //This is what I would like to do ideally
}
Run Code Online (Sandbox Code Playgroud)
我不能Ctrl1在里面使用,Ctrl2因为它是未定义的.但是,如果我尝试传递它...
function Ctrl2($scope, Ctrl1) {
$scope.prop2 = "Second";
$scope.both = Ctrl1.prop1 + $scope.prop2; //This is what I would like to do ideally
}
Run Code Online (Sandbox Code Playgroud)
我收到一个错误.有谁知道如何做到这一点?
干
Ctrl2.prototype = new Ctrl1();
Run Code Online (Sandbox Code Playgroud)
也失败了.
注意:这些控制器不是彼此嵌套的.
我有一个HTML表,想要$scope.records通过单击表头($scope.headers在ctrl中)对我的记录(在ctrl中)进行排序,
任何人都可以解释为什么这样做:
<th>
<a ng-click="sortColumn=headers[0];reverse=!reverse">{{ headers[0] }}</a>
</th>
<th>
<a ng-click="sortColumn=headers[1];reverse=!reverse">{{ headers[1] }}</a>
</th>
Run Code Online (Sandbox Code Playgroud)
那不是:
<th ng-repeat="header in headers">
<a ng-click="sortColumn=headers[$index];reverse=!reverse">{{ headers[$index] }}</a>
</th>
Run Code Online (Sandbox Code Playgroud)
以下是记录的代码:
<tr ng-repeat="arr in records | orderBy:sortColumn:reverse">
<td ng-repeat="val in arr" ng-bind-html-unsafe="arr[headers[$index]]</td>
</tr>
Run Code Online (Sandbox Code Playgroud)
我的表中有58列,所以循环表头更好...