问题列表 - 第13702页

JavaScript实例函数与原型函数

可能重复:
在Javascript中使用'prototype'与'this'?

我对各种JavaScript函数的理解如下:

function MyObj() {
    this.propOne = true;
    this.publicInstanceFunc = function() {
        if (propOne)
            return 'public instance function';
    }
    function privateFunc() {
        return 'private function only visible inside this constructor';
    }
}

MyObj.prototype.protoFunc = function() {
    if (this.propOne)
        return 'prototype function shared amongst all instances of MyObj';
}
Run Code Online (Sandbox Code Playgroud)
  1. 这些是正确的吗?
  2. 在什么情况下应该将函数放在原型(例如protoFunc)和构造函数(例如publicInstanceFunc)中?
  3. 使用this正确的方法访问原型函数内的属性?

javascript syntax prototype-programming

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

为什么我不能通过我的ViewData或模型进行操作?

我一直在尝试在视图中迭代我的ViewData时遇到错误...我甚至尝试将视图强行键入IEnumerable(App.Models.Namespace)并使用Model,但无济于事.要么因为缺少GetEnumerable方法或者无效的类型转换而出错...我知道我是怎么做到的吗?

模型...

public IQueryable<Product> getAllProducts()
{
    return (from p in db.Products select p);
}
Run Code Online (Sandbox Code Playgroud)

控制器...

public ActionResult Pricing()
{
    IQueryable<Product> products = orderRepository.getAllProducts();

    ViewData["products"] = products.ToList();

    return View();
}
Run Code Online (Sandbox Code Playgroud)

视图...

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    Pricing
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

    <h2>Pricing</h2>

    <div>
        <select class="product">
            <%foreach(var prod in ViewData["products"]){%>
                <option><%=prod.Title %></option>
            <%} %>

        </select><select></select>
    </div>

</asp:Content>
Run Code Online (Sandbox Code Playgroud)

asp.net-mvc ienumerable

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

字符串平铺算法

我正在寻找一种有效的算法来进行字符串平铺.基本上,你给出一个字符串列表,比如BCD,CDE,ABC,A,产生的瓷砖字符串应该是ABCDE,因为BCD与对齐CDE屈服BCDE,然后将其与对齐ABC得到最终ABCDE.

目前,我使用的是一种略显天真的算法,其工作原理如下.用随机对字符串的开始,说BCDCDE,我用下面的(在Java中):

public static String tile(String first, String second) {
  for (int i = 0; i < first.length() || i < second.length(); i++) {
    // "right" tile (e.g., "BCD" and "CDE")
    String firstTile = first.substring(i);
    // "left" tile (e.g., "CDE" and "BCD")  
    String secondTile = second.substring(i);
    if (second.contains(firstTile)) {
      return first.substring(0, i) …
Run Code Online (Sandbox Code Playgroud)

string algorithm tiling

12
推荐指数
1
解决办法
1745
查看次数

如何从c#刻录视频DVD?

我需要在C#应用程序中从我的网络摄像头刻录视频DVD吗?做正确的方法是什么?需要什么步骤?

我想我必须使用正确的文件夹结构和MPEG2视频创建图像,然后将其刻录到DVD?IMAPI2?

c# video dvd dvd-burning imapi

3
推荐指数
1
解决办法
3039
查看次数

Wordpress会话管理

我正在使用Wordpress建立一个网站,我想捎带它的会话.但我找不到任何插件,甚至文档.在我开始黑客攻击之前有任何建议或参考吗?

注意:我询问WP是否以及如何使用标准PHP会话本身,而不是如何使用session_start()添加PHP会话.显然任何WP所维持的状态都是通过其他方式完成的.因此,如果我想使用PHP会话,我需要完全自己添加和维护它,使用线程中的技术.

谢谢大家!

wordpress session-management

22
推荐指数
4
解决办法
4万
查看次数

较少从stderr获取键盘输入?

我正在看一下'less'实用程序的代码,特别是它如何获得键盘输入.有趣的是,在ttyin.c的第80行,它将文件描述符设置为:

     /*
      * Try /dev/tty.
      * If that doesn't work, use file descriptor 2,
      * which in Unix is usually attached to the screen,
      * but also usually lets you read from the keyboard.
      */
  #if OS2
      /* The __open() system call translates "/dev/tty" to "con". */
      tty = __open("/dev/tty", OPEN_READ);
  #else
      tty = open("/dev/tty", OPEN_READ);
  #endif
      if (tty < 0)
          tty = 2;
Run Code Online (Sandbox Code Playgroud)

是不是文件描述符2 stderr?如果是这样,WTH ?! 我以为键盘输入是通过stdin发送的.

有趣的是,即使你这样做ls -l * | less,在文件加载完成后,你仍然可以使用键盘上下滚动,但如果你这样做ls -l * | vi …

linux ubuntu gnu-coreutils

13
推荐指数
1
解决办法
1238
查看次数

有条件地执行函数的最佳方法是什么?

是的,我知道这个措辞很难理解,但这让我很烦恼.在最近的一个项目中,我有一个recurses函数,并且有许多条件会导致它停止递归(目前为三).哪种情况可选?(IE最佳性能或最简单的维护).

1)有条件退货:

void myRecursingFunction (int i, int j){
    if (conditionThatWouldStopRecursing) return;
    if (anotherConditionThatWouldStopRecursing) return;
    if (thirdConditionThatWouldStopRecursing) return;

    doSomeCodeHere();
    myRecursingFunction(i + 1, j);
    myRecursingFunction(i, j + 1);
}
Run Code Online (Sandbox Code Playgroud)

2)用if语句包装整个东西

void myRecursingFunction (int i, int j){
    if (
        !conditionThatWouldStopRecursing &&
        !anotherConditionThatWouldStopRecursing &&
        !thirdConditionThatWouldStopRecursing
    ){
        doSomeCodeHere();
        myRecursingFunction(i + 1, j);
        myRecursingFunction(i, j + 1);
    }
}
Run Code Online (Sandbox Code Playgroud)

3)你做错了noob,没有理智的算法会使用递归.

c# recursion

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

SQLite用于连接表

我如何将以下语句从MySQL-ese转换为SQLite-ese?

UPDATE Attribute, Name 
  SET Attribute.AttValue = 'foobar'
  WHERE Attribute.NameID = Name.NameID 
    AND Name.Name = 'rotate_ccw'
Run Code Online (Sandbox Code Playgroud)

看起来SQLite不支持UPDATE语句中的连接.

sql sqlite

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

IE6 CSS Hover问题菜单

我有一个CSS悬停菜单,适用于所有浏览器,除了...惊喜 - IE6!

#menu_right ul li:hover ul { visibility: visible; }
Run Code Online (Sandbox Code Playgroud)

ul显然,这最初是隐藏的.当我将鼠标悬停在其父级上时li,它应该显示...但它没有.

为了确定问题,我尝试使ul最初可见并让悬停动作采取其他措施.例如:

#menu_right ul li ul { visibility: visible; }

#menu_right ul li:hover ul { background: red; }
Run Code Online (Sandbox Code Playgroud)

这没有用.在其他浏览器(包括IE7 +)上,ul当我将鼠标悬停在其父级上时,它将变为红色list element.但不是在IE6中.我错过了什么?

html css compatibility hover internet-explorer-6

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

如何在git中列出版本化文件?

我想在git存储库的根目录中列出版本化文件.要在集市上做同样的事情,你运行:

bzr ls --versioned --non-recursive
Run Code Online (Sandbox Code Playgroud)

我怎么用git做这个?

git bazaar

28
推荐指数
2
解决办法
8195
查看次数