Tag: 作用域

在Angular JS中把用户定义的函数放在哪里?

在我看来,我想渲染: <p> {{ say() }} </p> 在哪里被定义如此: say = function() { return "Hello World"; } 我可以在我的控制器中定义它: function TestCtrl($scope) { $scope.say = function() { … }; } 但是只能在该控制器内访问。 如果我在Angular文件结构之外定义函数,则不呈现任何内容。 如果我在我的controllers.js文件中定义它,但在控制器函数作用域之外,则是相同的。 在哪里放置我的function,所以我可以渲染它在任何控制器?

Python:在其中的模块和类之间共享全局variables

我知道可以在Python中跨模块共享一个全局variables。 但是,我想知道这是可能的程度,为什么。 例如, global_mod.py x = None mid_access_mod.py from global_mod import * class delta: def __init__(self): print x bot_modif_mod.py import mid_access_mod import global_mod class mew: def __init__(self): global_mod.x = 5 def main(): m = mew() d = mid_access_mod.delta() 这将打印None,即使所有模块共享全局variablesx。 这是为什么? 在me_m()被分配到bot_modif_mod.py之前,似乎x在mid_access_mod.py处被评估。

参数错误:范围正文需要被调用

我正在通过“Ruby On Rails 3基本培训”工作,并且在使用名称范围时遇到了问题。 当findlogging和使用Rails控制台查询时,一切都很顺利,直到我试图在我的subject.rb文件中使用一个名称范围。 这是我的代码在subject.rb文件。 Class Subject < ActiveRecord::Base scope :visible, where(:visible => true) end 我保存了.rb文件并重新启动了我的Rails控制台,但是当我从rails控制台运行时: subjects = Subject.visible 我得到: ArgumentError: The scope body needs to be callable. 有谁知道为什么我得到这个错误。

如何检查一个指令的方法参数是否在AngularJS中指定?

我创build了一个包含一个button的自定义指令。 该button从“callback”属性指定的父范围中调用一个方法。 <!DOCTYPE html> <html ng-app="app"> <head> <title>Simple directive</title> <script src="js/lib/angular/angular.js"></script> <script type="text/javascript"> var app = angular.module('app', []); app.controller('TestController', function($scope) { $scope.doSomething = function(param) { alert('Something called with: ' + param); } }) app.directive('myDirective', function() { var ret = { restrict: 'E', scope: { user: '@', callback: '&' // bound a function from the scope […]

在ECMAScript5中,“严格使用”的范围是什么?

ECMAScript5中严格模式编译指示的范围是什么? "use strict"; 我想这样做(主要是因为JSLint没有抱怨): "use strict"; (function () { // my stuff here… }()); 但我不确定是否会破坏其他代码。 我知道,我可以做到这一点,这将编译范围的function… (function () { "use strict"; // my stuff here… }()); 但JSLint抱怨(当“strict”JSLint选项被启用时),因为它认为你在启用“use strict”之前执行的代码。 这是我的问题。 如果我有fileA.js: "use strict"; // do some stuff 和fileB.js: eval( somecodesnippet ); // disallowed by "use strict" 然后按照相同的顺序将它们包含在我的html页面中,这个编译指示是否会被限制到文件中,或者这个编译指示是否会stream入到fileB中,从而阻止了eval的执行?

Rails的范围是不是空的,不是空的/空的?

我有以下范围: scope :comments, :conditions => ['text_value IS NOT NULL'] 但是我也想要条件说“OR text_value不是空的”(或者是这个效果)。 我不想selecttext_value为空/空白的任何行。

多个指令要求新/隔离范围

我写了一个对话框指令(myPopup),另一个用于拖动这个对话框(myDraggable),但是我总是得到这个错误: 多个指令[myPopup,myDraggable]要求新/隔离范围 这是一个Plunker: http ://plnkr.co/edit/kMQ0hK5RnVw5xOBdDq5P?p=preview 我能做什么? JS代码: var app = angular.module('myApp', []); function myController($scope) { $scope.isDraggable = true; } app.directive('myPopup', [ function () { "use strict"; return { restrict: 'E', replace: true, transclude: true, template: '<div my-draggable="draggable"class="dialog"><div class="title">{{title}}</div><div class="content" ng-transclude></div></div>', scope: { title: '@?dialogTitle', draggable: '@?isDraggable', width: '@?width', height: '@?height', }, controller: function ($scope) { […]

如何使用Emacs Lispdynamic范围界定?

我以前学过Clojure,非常喜欢这种语言。 我也爱Emacs,并用Emacs Lisp破解了一些简单的东西。 但是有一件事情可以让我在精神上阻止Elisp做更多的事情。 这是dynamic范围的概念。 我只是害怕它,因为它对我来说太陌生了,闻起来像是半全球variables。 所以对于variables声明,我不知道哪些事情是安全的,哪些是危险的。 从我所了解的情况来看,使用setq设置的variables属于dynamic范围(是吗?)让variables怎么样? 我读过的一些地方,让你做简单的词法作用域,但是我读的其他地方,让vars也dynamic范围。 我最担心的是我的代码(使用setq或let)意外地打破了我调用的平台或第三方代码中的一些variables,或者在这样的调用之后,我的本地variables意外地混乱了。 我怎样才能避免这一点? 是否有一些简单的经验法则,我可以遵循,准确地知道范围发生了什么,而不会被一些奇怪的,难以debugging的方式咬伤?

在python中从内部类访问外部类

我有这样的情况 class Outer(object): def some_method(self): # do something class Inner(object): def __init__(self): self.Outer.some_method() # <– this is the line in question 我如何从Inner类访问Outer类的方法? 编辑 – 感谢您的答复。 我得出结论,我需要重新评估我是如何devise这个实现的,并提出一个更强大的方法。

ActiveRecord的Rails 3范围与类的方法

我是新来的ActiveRecord的新查询接口,所以我仍然搞清楚事情。 我希望有人可以解释在ActiveRecord模型中使用scope和仅使用类方法(即self.some_method )之间的self.some_method 。 从我所能得到的结果来看,一个范围总是被期望返回一个关系,而一个类方法并不一定非要。 这是真的? 例如,我认为这样做是有道理的: class Person scope :grouped_counts, group(:name).count end 但是这不起作用。 我得到这个错误: ArgumentError: Unknown key(s): communicating, failed, matched, unmatched from /Users/bradrobertson/.rvm/gems/ruby-1.9.2-p180@influitive/gems/activesupport-3.0.5/lib/active_support/core_ext/hash/keys.rb:43:in `assert_valid_keys' from /Users/bradrobertson/.rvm/gems/ruby-1.9.2-p180@influitive/gems/activerecord-3.0.5/lib/active_record/relation/spawn_methods.rb:110:in `apply_finder_options' from /Users/bradrobertson/.rvm/gems/ruby-1.9.2-p180@influitive/gems/activerecord-3.0.5/lib/active_record/named_scope.rb:110:in `block in scope' from (irb):48 from /Users/bradrobertson/.rvm/gems/ruby-1.9.2-p180@influitive/gems/railties-3.0.5/lib/rails/commands/console.rb:44:in `start' from /Users/bradrobertson/.rvm/gems/ruby-1.9.2-p180@influitive/gems/railties-3.0.5/lib/rails/commands/console.rb:8:in `start' from /Users/bradrobertson/.rvm/gems/ruby-1.9.2-p180@influitive/gems/railties-3.0.5/lib/rails/commands.rb:23:in `<top (required)>' from script/rails:6:in `require' from script/rails:6:in `<main>' r 它不过是一个类方法 def self.grouped_counts […]