标签: anonymous

覆盖google.com匿名函数的一部分

如果匿名声明了javascript函数,有没有办法覆盖它或它的一部分?

我试图阻止google.com的即时搜索从劫持上下箭头键移动搜索排名.我已经确定了我认为有问题的代码部分.键码38和40用于向下和向上键.

if (b == 40) aa(f);
else if (b == 38) aa(j);
else if (b == 37 || b == 39) if (!ca(b == 39)) return f;
a.preventDefault && a.preventDefault();
return a.returnValue = j
Run Code Online (Sandbox Code Playgroud)

问题是这是一个名为Sb = function(a){}的函数的一部分,它位于大约三千行的匿名函数中.在这里发布了一个类似的问题,作者最终以一种不适合我的黑客方式进行工作.我意识到我可以关闭即时搜索,但我喜欢它,我无法忍受我的箭头键不再工作.

解:

我最终编写了一个chrome扩展来恢复向上/向下箭头键功能以滚动.我使用了以下代码.谢谢Raze和Mofle.

if (event.keyCode == 40 || event.keyCode == 38)  {
    event.cancelBubble = true;
    event.stopPropagation();            
    return false;
}
Run Code Online (Sandbox Code Playgroud)

javascript overriding anonymous function

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

AS3中的匿名功能有什么用?

我遇到过它们,但我还没有明白为什么要使用它们.有人可以解释一下吗?

flash anonymous function actionscript-3

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

匿名类建设

我需要一个在PHP上创建匿名类的想法.我不知道我的工作方式.

看我的局限:

  • 在PHP上你不能像匿名函数那样创建匿名类(如class {});
  • 在PHP上你没有类范围(名称空间除外,但它在下面有相同的问题);
  • 在PHP上,你不能使用变量来指定类名(如class $name {});
  • 我没有权限安装runkitPECL.

我需要什么,为什么:

好吧,我需要创建一个名为ie的函数create_class(),它接收一个键名和一个匿名类.它对我有用,因为我想使用PHP无法接受的不同名称类符号.例如:

<?php

  create_class('it.is.an.example', function() {
    return class { ... }
  });

  $obj = create_object('it.is.an.example');

?>
Run Code Online (Sandbox Code Playgroud)

所以,我需要一个接受这种用法的想法.我需要它,因为在我的框架中我有这条道路:/modules/site/_login/models/path/to/model.php.所以,model.php需要声明一个叫做的新类site.login/path.to.model.

在调用时,create_object()如果内部缓存有一个$class定义(就像it.is.an.example它只是返回新的类对象.如果没有,需要加载.所以我将使用$class内容快速搜索什么是类文件.

php namespaces anonymous class php-7

9
推荐指数
3
解决办法
6745
查看次数

UILabel(CALayer)正在使用大量虚拟内存

Xcode and Instruments我看到UILabel (CALayer)使用大量的虚拟内存(匿名VM).我看到每个大约235 KB的虚拟内存UILabel.

我认为这可能是iOS 7.1或7.1.1的新问题.

这是预期的吗?

我创建了一个简单的程序,创建500 UILabelsInstruments显示115MB的内存使用.在大约1500个标签处,应用程序由OS终止.

for (int i = 0; i < 500; i++)
{
    index = (int)[self.items count];
    index++;

    frame = CGRectMake(10.0, 20, 300.0, 50.0);

    UILabel *newLabel = [[UILabel alloc] initWithFrame:frame];
    newLabel.text = [NSString stringWithFormat:@"This is text for label: %d", index];
    newLabel.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:newLabel];

    [self.items setObject:newLabel forKey:[NSNumber numberWithInteger:index]];
}
Run Code Online (Sandbox Code Playgroud)

思考?

xcode anonymous virtual-machine instruments ios

9
推荐指数
2
解决办法
3508
查看次数

迁移匿名配置文件的最佳方式

是否存在隐式迁移所有参数的替代方法?或任何其他优点.

来自MSDN:

public void Profile_OnMigrateAnonymous(object sender, ProfileMigrateEventArgs args)
{
  ProfileCommon anonymousProfile = Profile.GetProfile(args.AnonymousID);

  Profile.ZipCode = anonymousProfile.ZipCode;
  Profile.CityAndState = anonymousProfile.CityAndState;
  Profile.StockSymbols = anonymousProfile.StockSymbols;

  ////////
  // Delete the anonymous profile. If the anonymous ID is not 
  // needed in the rest of the site, remove the anonymous cookie.

  ProfileManager.DeleteProfile(args.AnonymousID);
  AnonymousIdentificationModule.ClearAnonymousIdentifier(); 

  // Delete the user row that was created for the anonymous user.
  Membership.DeleteUser(args.AnonymousID, true);

}
Run Code Online (Sandbox Code Playgroud)

或者这是最好/唯一的方式?

asp.net profiling anonymous migrate

8
推荐指数
1
解决办法
1592
查看次数

C#委托编译器优化

我已经开始在C#中大量使用匿名委托了,我开始怀疑编译器或运行时从实际运行的代码中删除它们的效率如何,我还没有在任何地方看到过详细的内容?

是否足够聪明地内联它们并崩溃可以静态推导的递归用法?

c# optimization delegates jit anonymous

8
推荐指数
1
解决办法
1005
查看次数

如何在应用程序关闭时终止Delphi中的匿名线程?

我有一个Delphi应用程序,它在一些TTimer.OnTimer事件中产生了6个匿名线程.

如果我从标题栏中的X按钮关闭应用程序,则会引发地址$ C0000005处的访问冲突,并且FastMM报告泄漏的TAnonymousThread对象.

哪个是使用TThread.CreateAnonymousThread()方法在OnTimer事件中创建的Delphi中释放匿名线程的最佳方法?

解决方案对我有用:

创建了一个匿名线程的包装器,它在被Free-ed时终止它们.

type
  TAnonumousThreadPool = class sealed(TObject)
  strict private
    FThreadList: TThreadList;
    procedure TerminateRunningThreads;
    procedure AnonumousThreadTerminate(Sender: TObject);
  public
    destructor Destroy; override; final;
    procedure Start(const Procs: array of TProc);
  end;

{ TAnonumousThreadPool }

procedure TAnonumousThreadPool.Start(const Procs: array of TProc);
var
  T: TThread;
  n: Integer;
begin
  TerminateRunningThreads;

  FThreadList := TThreadList.Create;
  FThreadList.Duplicates := TDuplicates.dupError;

  for n := Low(Procs) to High(Procs) do
  begin
    T := TThread.CreateAnonymousThread(Procs[n]);
    TThread.NameThreadForDebugging(AnsiString('Test thread N:' + IntToStr(n) + ' TID:'), T.ThreadID);
    T.OnTerminate := AnonumousThreadTerminate;
    T.FreeOnTerminate := true; …
Run Code Online (Sandbox Code Playgroud)

delphi multithreading anonymous terminate delphi-xe2

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

实体框架`AsNoTracking`不能与匿名投影一起使用

在下面剪断我尝试使用获取数据Anonymous Projection,我想不跟踪entities获取的数据.

注意:我已经完成了现有的堆栈问题,但无法为我找到有效的解决方案

using (var db = new Entities())
{
     db.Configuration.LazyLoadingEnabled = false;
     db.Configuration.ProxyCreationEnabled = false;

     var myprojection = db.Table1
                        .AsNoTracking()
                        .Include(gh=>gh.Table2) //Update
                        .Include(gh=>gh.Table3) //Update
                        .Select(x => new
                        {
                            table1= x,
                            table2= x.Table2.Where(g => Some Condition),

                            table3= x.Table3.Where(g=>Some Condition)
                        })
                        .ToList();

    var result = myprojection.Select(g =>g.table1).FirstOrDefault();

}
Run Code Online (Sandbox Code Playgroud)

当我使用AsNoTracking()内部表格中的数据(表格2,3)在此行的转换过程中丢失var result = myprojection.Select(g =>g.table1).FirstOrDefault();

编辑

如果我删除AsNoTracking()一切正常.

1)如何使用projectionAsNoTracking在实体框架是否正确?

2)删除此查询的跟踪的任何其他选项?

有没有可能的解决方法?

.net c# linq entity-framework anonymous

8
推荐指数
1
解决办法
4099
查看次数

在jQuery中将函数作为参数传递?

我想传递给jQuery函数一个常规函数,而不是通常的匿名函数,但我不确定如何做这样的事情.

而不是这个:

function setVersion(feature) {
      $.post("some.php", { abc:"abc" },
      function(data){
         // do something here
      }, "json");
}
Run Code Online (Sandbox Code Playgroud)

我想这样做:

function foo(data){
   // do something here
}

function setVersion(feature) {
      $.post("some.php", { abc:"abc" }, foo, "json");
}
Run Code Online (Sandbox Code Playgroud)

谢谢.

javascript parameters jquery anonymous function

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

在LINQ to SQL中动态构造"或"LIKE查询

我有一个由匿名对象组成的LINQ查询.

在给定的点上,我想通过传入的搜索参数来限制结果,但这可以是一个或多个参数,并且我想使用这些参数执行"LIKE x OR LIKE y OR LIKE z".

在代码中,它看起来像这样:

reservations = reservations.Where(r =>
  r.GuestLastName.Contains(parameter1) || r.GuestFirstName.Contains(parameter1) || 
  r.GuestLastName.Contains(parameter2) || r.GuestFirstName.Contains(parameter2) || 
  // Parameter 3, 4, 5,..
);
Run Code Online (Sandbox Code Playgroud)

我怎么能动态地构造它,知道它reservationsIQueryable<'a> (anonymous object)什么类型?我查看了各种资源,当我知道类型时,我似乎只能找到一种方法,而不是在使用匿名类型时.

重要的是要知道它是Linq to SQL,因此它应该被转换为SQL查询而不是在内存中过滤...

c# linq anonymous linq-to-sql

7
推荐指数
1
解决办法
1278
查看次数